Select.selectedIndex

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

							select.selectedIndex

Description

The selectedIndex property of the Select object returns the index number of the selected option in that instance of a select box. If this property is used to access a multiple select box, it will return the index number of the first selected item.

Example

Listing 7.477 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.477 Accessing the selectedIndex Property of the Select Object
 <form name="myForm"> <select name="mySelect" onChange='alert(mySelect.selectedIndex)'> <option value=HOCK>Hockey</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.