selectedIndex property

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

Syntax

HRESULT value = object.put_selectedIndex( index);HRESULT value = object.get_selectedIndex(* index);

Property values

Type: long

the index.

Standards information

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 IHTMLSelectElement::selectedIndex property, the display of the select object updates immediately.

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

The IHTMLSelectElement::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 IHTMLSelectElement::multiple attribute is not specified. If the IHTMLSelectElement::multiple attribute is specified for a select object, the IHTMLSelectElement::selectedIndex property returns only the index of the first selected item, if any.

The IHTMLOptionElement::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 IHTMLSelectElement::multiple attribute is specified. You can use the IHTMLOptionElement::selected property to determine whether an individual item in a select object is selected. In addition, selected items are not cleared when the IHTMLOptionElement::selected property is set. This allows multiple items in the list to be selected at the same time.