Archive for May 24, 2007

JavaScript selectedIndex property

Posted in JavaScript, Software, Web, internet, programming on May 24, 2007 by Joey

The selectedIndex property of a dropdown select list can be accessed via JavaScript as follows:

select name="SelectBox" onChange="alert(this.selectedIndex);"

The preceding example shows that selectedIndex is a property of the dropdown select list. selectedIndex is 0-based, meaning that the first item in the select list has a selectedIndex of 0; the second item in the select list has a selectedIndex of 1; and so forth. If nothing is selected, the selectedIndex is -1.

Related articles:
JavaScript: How to Get Selected Item in Dropdown Select List
Accessing Form Elements with JavaScript