Indicates the index of the currently selected item.
Syntax
object.selectedIndex[ = index]
Parameters
object
A Listbox script object.
index
Specifies the index of the currently selected item as described in the following table.
Setting | Description |
-1 | Indicates no item is currently selected. |
0 or Positive integer | Indicates the index of the currently selected item. The index is zero-based. |
Remarks
The index of the first item in the list is 0. The getCount method is always 1 greater than the value of selectedIndex.
Example
Uses the window onload event in DHTML to fill a listbox.
function window_onload()
{
for ( i=0; i<5; i++)
{
myListbox.addItem("Item " + i );
}
myListbox.selectedIndex = 3; // select the 4th item
}