| JAVASCRIPT: FORMS:
Retrieving the selected item in a combo list |
|
|
|
Sample: The text field is
refreshed when the option in the combo changes |
|
|
|
Properties, methods, events and
objects used |
|
|
For the text box
For the combo list
- property selectedItem
- collection options of option objects
- property value of option object
- event onchange (you can also use onclick, ideal if there
is no pre-selected option in the list). Onchange will only
trigger when the current selectedIndex changes. If you did
not explicity pre-select an option (by including the
attibute "selected" in the <option> tag),
by default selectedIndex = 0. If the user cliks in the 1st
element then, the text box won't be updated with an
onchange, it will with a onclick. But if the user doesn't
use the mouse click to select (he uses the cursor keys),
onclick will be unuseful, thus your best bet will be to
program both events with the same code. Briefly: if you
have a pre-selected item in the list, use onchange, if not
program onchange and onclick.
|
|
|
The Code |
|
|
|
Remember! |
|
|
- JS is case sensitive in variables names and in reserved
words (selectedIndex <> SelectedIndex)
- If you have a pre-selected value in the list, you have to
load in code that value in the associated text box at the
beginning
|
|
|
|