selectedIndex
(attribute
)
Owning interface and usage:
Member of these other interfaces:
none
Readonly: no
Description:
The ordinal index of the selected option, starting from 0. The value -1 is returned if no element is selected. If multiple
options are selected, the index of the first selected option is returned.
Example:
Source:
<SELECT id="component-select">
<OPTION value="Component_1_a">Component_1</OPTION>
<OPTION value="Component_1_b">Component_2</OPTION>
<OPTION value="Component_2_a" selected="selected">Component_3</OPTION>
<OPTION value="Component_2_b">Component_4</OPTION>
</SELECT>
JavaScript:
function showSelectedIndex() {
var main = document.getElementById('component-select');
alert('Selected option has index nr. '+main.selectedIndex);
}
See it:
Component_1
Component_2
Component_3
Component_4