selectedIndex Property

DHTML, HTML, & CSS

selectedIndex Property


Sets or retrieves the index of the selected option in a SELECT object.

Syntax

HTMLN/A
Scriptingselect.selectedIndex [ = iIndex ]

Possible Values

iIndexInteger that specifies the index.

The property is read/write with no default value.

Expressions can be used in place of the preceding value(s), as of Microsoft® Internet Explorer 5. For more information, see dynamic propertiesInternet Link.

Remarks

Options in a SELECT object are indexed in the order in which they are defined, starting with an index of 0. When you set the selectedIndex property, the display of the SELECT object updates immediately.

The selectedIndex property returns -1 if a SELECT object does not contain any selected items. Setting the selectedIndex property clears any existing selected items.

The selectedIndex property is most useful when used with SELECT objects that support selecting only one item at a time—that is, those in which the MULTIPLE attribute is not specified. If the MULTIPLE attribute is specified for a SELECT object, the selectedIndex property returns only the index of the first selected item, if any.

The selected property is most useful when used with SELECT objects that support selecting more than one item at a time—that is, those in which the MULTIPLE attribute is specified. You can use the selected property to determine whether an individual item in a SELECT object is selected. In addition, selected items are not cleared when the selected property is set. This allows multiple items in the list to be selected at the same time.

Example

This example uses the selectedIndex property to retrieve individual values from a SELECT object. When a site is selected from the list, the browser displays the associated page.

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://msdn.microsoft.com">
    Developer Network</OPTION>
</SELECT>

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
HTML N/A
Scripting SELECT

Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.