Magazine |
| | Community |
| | Workshop |
| | Tools & Samples |
| | Training |
| | Site Info |
|
|
||||||||
|
Sets or retrieves an integer specifying the index of the selected option in a SELECT object.
Syntax
HTML N/A Scripting select.selectedIndex [ = iIndex ]
Possible Values
iIndex Integer specifying the index. The property is read/write with no default value.
Remarks
Options in a SELECT object are indexed in the order in which they are defined, starting with an index of zero. You can set the selectedIndex property at any time. The display of the SELECT object updates immediately when you set the selectedIndex property. Both forms of the syntax specify the same value.
In general, this property is more useful for SELECT objects that are created without the multiple attribute. If you evaluate selectedIndex when multiple options are selected, the selectedIndex property specifies the index of the first option only. Setting selectedIndex clears any other options that are selected in the SELECT object.
The selected property of the select object's options array is more useful for SELECT objects that are created with the MULTIPLE attribute. With the selected property, you can evaluate every option in the options array to determine multiple selections, and you can select individual options without clearing the selection of other options.
Example
In the following example, the user will be taken to the URL selected from the options as long as it is a change from the default value showing in the select list.
Sample Code
<SELECT onchange="window.location.href=this.options[this.selectedIndex].value"> <OPTION VALUE="http://www.microsoft.com/ie">Internet Explorer</OPTION> <OPTION VALUE="http://www.microsoft.com">Microsoft Home</OPTION> <OPTION VALUE="http://www.microsoft.com/msdn">Developer Network</OPTION> </SELECT>
Applies To
HTML N/A Scripting SELECT
Does this content meet your programming needs? Write us!
© 1998 Microsoft Corporation. All rights reserved. Terms of use.