OK, well the selectedIndex doesn't rely upon the populated values or text displayed by the select element. The selectedIndex is simply a number that refers to which item is selected. To make this a bit clearer, we could have this:
HTML Code:
<form action="">
<select onchange="if (this.selectedIndex==2){this.form['box'].style.visibility='visible'}else {this.form['box'].style.visibility='hidden'};">
<option value="">Bob</option>
<option value="">Henri</option>
<option value="">Martin</option>
<option value="">Jessica</option>
</select>
<input style="visibility:hidden;" type="text" name="box">
</form>
and it would still work. Selecting 'Martin' would reveal the text input. I used the numbers in my example just to show the selectedIndex of each option. Each will have that selectedIndex no matter what it displays and no matter what its value attribute is set to.
If you need to populate and set which selectedIndex reveals the box, you will need to populate this number (red) as well as the options themselves:
Code:
<select onchange="if (this.selectedIndex==2){this.form['box'].style.visibility='visible'}else {this.form['box'].style.visibility='hidden'};">
The selectedIndex is always numbered from 0 to whatever on down the list of available options.
Bookmarks