View Full Version : Is selectedindex standard?

12-02-2008, 12:09 AM
Hi all,

Not having a lot of luck with Google:


My best guess from these results is that selectedIndex is standard in HTML5?

Do I need to be careful when using selectedIndex? Is it standard, or just quasi-de facto standard like innerHTML?

Thanks guys.

12-02-2008, 03:24 AM
selectedIndex is a standard based on DOM level 1 (http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-94282980)

12-02-2008, 05:59 AM
Yes it is standard in javascript. It generally has no useful cross browser value without reference to a select element and its option(s) of which one is selected though. Consider:


That's (assuming that select_element exists and has at least one option that is selected) a number (0 to whatever).

Any other use may or may not have any value in any given browser, although a select element with no options (technically invalid), or no option selected will generally have a options.selectedIndex that is out of range (usually -1, or possibly NaN, etc.).

All of this probably sounds complicated because it is just the general description of its possible usage. If so, and there is something in particular that you wold like to do, give us the details and we can probably help a lot more.

12-02-2008, 06:27 PM
Thanks a bunch for your responses. It's working out fine, just wanted to make sure I wouldn't find out later that my app is broken in some lesser used browser.

12-03-2008, 04:31 AM
I should have also mentioned that the selectedIndex is a setter as well as a getter. That means that it may be used via javascript to set which option is selected.