JavaScript Reference/Javascript Properties/selectedIndex
"selectedIndex" Example
<source lang="javascript">
<html> <body> <script> function function1(colors) {
var col = (colors.options[colors.selectedIndex].value); if (col) { document.bgColor = col; } alert("SelectedIndex value = "+col);
} </script> <form method="post" action=""> <select name="colors" onChange="function1(this);">
<option value="white" selected>White</option> <option value="cyan">Cyan</option> <option value="ivory">Ivory</option> <option id="myO" value="blue">Blue</option> <option value="red">Red</option> <option value="lightblue">Lightblue</option> <option value="beige">Beige</option>
</select> </form>
</source>
"selectedIndex" is applied to
<source lang="javascript">
+----------------+--------------------------------------------------------------+ | Applied_To |<select> | +----------------+--------------------------------------------------------------+
</source>
"selectedIndex" Syntax and Note
<source lang="javascript">
Note: Read and write property. The index of the selected <option> element.
Syntax:
document.getElementById("selectID").selectedIndex = value document.all.selectID.selectedIndex = value // IE only
</source>