Getting the Valu From Dropdown and Setting it as TextBox Text

C

Charleees

Hi all,

I have a DropDown and a TextBox just bekeow it...

I have to get the selected value from dropdown and set it as textBox
Text..

The thing is i have to do this Without PostBack.....

Is there any java script to do this functionality...

please reply..

Thanks in Advance..

Sanju.C
 
R

Randy Webb

Charleees said the following on 6/5/2006 1:10 AM:
Hi all,

I have a DropDown and a TextBox just bekeow it...

I have to get the selected value from dropdown and set it as textBox
Text..

The thing is i have to do this Without PostBack.....

Is there any java script to do this functionality...

please reply..

Do I get your grade on your homework as well?

that.value = this.value;

Where that is the textbox, this is the select, search the archives for
the rest and the resolution of getting this and that right.
 
B

Bart Van der Donck

Charleees said:
I have a DropDown and a TextBox just bekeow it...
I have to get the selected value from dropdown and set it as textBox
Text..
The thing is i have to do this Without PostBack.....
Is there any java script to do this functionality...

I think you're looking for something like this:

<form name="myForm">
<select name="F1" size="1"
onChange="document.myForm.F2.value=this.value">
<option value="value1">value1</option>
<option value="value2">value2</option>
<option value="value3">value3</option>
<option value="value4">value4</option>
</select>
<input type="text" name="F2" size="10" value="value1">
</form>
 
R

Randy Webb

Bart Van der Donck said the following on 6/5/2006 9:00 AM:
I think you're looking for something like this:

And just think, they didn't have to do anything other than ask and
someone writes a solution for them. Aint Usenet grand?
 
B

Bart Van der Donck

Randy said:
[...]
And just think, they didn't have to do anything other than ask and
someone writes a solution for them.

Yes, you're right of course - I hope the OP liked my pre-fabricated,
tasty cookie with its cool packing design! :)
Aint Usenet grand?

Definitely - When it comes to technical accuracy, you can trust (some
groups on) usenet (on some type of questions): I mean, if someone's
wrong, somebody else will correct him :) That so-called "battle test"
is the best guarantee for software quality.

It's good for the OP to read this kind of posts as well, and do some
further study to get better insight in the technologies he's using.
Considering his sort of question, that insight is probably still quite
low at this moment.
 
R

Richard Cornford

Bart said:
Randy Webb wrote:

Definitely - When it comes to technical accuracy, you can trust
(some groups on) usenet (on some type of questions): I mean, if
someone's wrong, somebody else will correct him :) That so-called
"battle test" is the best guarantee for software quality.
<snip>

That is pretty much an invitation to have someone quibble about your
code ;-)

So here goes:-

| <form name="myForm">

In valid HTML a FORM attribute is required to have an ACTION attribute.
Because of the issues arising directly from attempting to script the
DOMs created from structurally invalid mark-up it is proposed that
mark-up examples, even fragments, should be valid. That is probably
going too far as no evidence has yet been presented that invalid and
missing attributes contribute to scripting issues.

| <select name="F1" size="1"

In a SELECT element that is not MULTIPLE does a - sive="1" - attribute
do anything worthwhile?

| onChange="document.myForm.F2.value=this.value">

You have elected to use the non-(W3C HTML DOM) standard 'shortcut'
property accessors of accessing the FORM element as a property of the
document and the form control as a property of the FORM element.

The W3C HTML DOM standard, and fully back-compatible alternative:-

document.forms['myForm'].element['F1'].value

(or dot notation equivalent) is preferred because it is:-

1. Self documenting, in that looking at the property accessor makes it
obvious that the - document.forms['myForm'] - is a reference to a
form, and that - .element['F1'] - is a reference to an element
(control) within that form. While - document.myForm - may be
confused with references to IMG, EMBED and some other elements that
may also be made available as 'shortcut' named properties of a
document (the name not withstanding as the name of a form in a
non-example should probably say something about the role of the
form), and - .F1 - may be confused with a reference to a property
of the FORM element (some host provided property or an expando).

2. Supported in a wider range of DOMs (as there are good reasons not
to expect XHTML DOMs to support any 'shortcut' property accessors).

However, all form controls have a - form - property that refers to the
form that contains them (or is null if they are not contained in a form)
so the left hand side of the assignment could be shortened to:-

this.form.element['F1'].value

Which makes the form access anonymous (so more flexible/portable).

Although the W3C HTML DOM does specify that the currently selected
OPTION's value be reproduced as a - value - property of the SELECT
element using this sacrifices some back-compatibility with Netscape 4
and some of its contemporaries. The Equally standard:-

this.options[this.selectedIndex].value

- reliably retrieves the value of the selected OPTION in all browsers
known to expose SELECT elements for scripting.

Leaving the assignment as:-

this.form.element['F1'].value = this.options[this.selectedIndex].value;

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top