Javascript Reference
Categories: SELECT

javascript SELECT selectedIndex

@July 25, 2008, 2:09 p.m.
selectedIndex Firefox/Netscape/NN 2 IE 3 Chrome/Safari/DOM 1  



This is the zero-based integer of the option selected by the user. If the select element is set to allow multiple selections, the selectedIndex property returns the index of the first selected item (see the selected property). You can use this property to gain access to the value or text of the selected item, as shown in the example.


In recent browsers, if no option is selected, the selectedIndex property returns -1. Setting the value to -1 to deselect all items works as you'd expect in IE 5 and later for Windows. For Netscape 6, setting the property to -1 may not empty the displayed option, but it does effectively deselect all items for a submitted form.

var list = document.forms[0].selectList;
var listText = list.options[list.selectedIndex].text;




Powered by Linode.