Select.options.selectedIndex

JavaScript1.0+, JScript1.0+ Nav2+, IE3+, Opera3+ Syntax

							select.options.selectedIndex

Description

The selectedIndex property of the options array of the Select object returns the index number of the selected option in that instance of a select box.

Example

Listing 7.475 has a single select box. When the user makes a selection, the onChange event handler is used to pop up an alert box that displays the index number of the selected option in this select box.

Listing 7.475 Accessing the selectedIndex Property of the options Array of a Select Object
 <form name="myForm"> <select name="mySelect" onChange='alert(mySelect.options.selectedIndex)'> <option value=HOCK>Hockey</option> <option value=RUG>Rugby</option> ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.