OPTION | NN 2 IE 3 DOM 1 | ||||
The OPTION object reflects the OPTION element, which must be nested inside a SELECT element. References to OPTION objects most often use its parent SELECT object, with the OPTION object treated as one member of an array of options belonging to that SELECT object. | |||||
HTML Equivalent<OPTION> | |||||
Object Model Reference
|
defaultSelected | NN 2 IE 3 DOM 1 | ||
Read/Write | |||
Whether element has the SELECTED attribute set in the tag. You can compare the current selected property against defaultSelected to see whether the state of the select control has changed since the document loaded. Changing this property does not affect the current selected status. | |||
Examplevar listItem = document.forms[0].selector.options[2]
if (listItem.selected != listItem.defaultSelected) {
process for changed state
} | |||
Value Boolean value: true | false. | |||
|
index | NN 2 IE 3 DOM n/a | ||
Read-only | |||
Returns the zero-based index value of the current option object within the collection of options of the SELECT element. The select object's selectedIndex property returns the index value of the option that is currently selected. Since you usually access an OPTION object via its place in the options array, there is little need to reference this property. | |||
Examplevar firstValue = document.forms[0].stateList.options[0].index | |||
Value Integer. | |||
|
selected | NN 2 IE 3 DOM 1 | ||
Read/Write | |||
Whether the list option has been selected by the user, meaning that its value is submitted with the form. Scripts can modify the value to select an item algorithmically. To find out which option is selected, it is more efficient to use the select object's selectedIndex property, rather than looping through all options in search of those whose selected properties are true. The exception to this is when the SELECT element is set to allow multiple selections, in which case you need to cycle through them all to find the chosen items. | |||
Exampledocument.forms[0].selectList.options[3].selected = true | |||
Value Boolean value: true | false. | |||
|
text | NN 2 IE 3 DOM 1 | ||
Read/Write | |||
The text associated with the OPTION element. This text is between the start and end tags and is what appears in the SELECT element on screen. A hidden value associated with the list item can be stored, retrieved, and changed via the value property. | |||
Examplevar list = document.forms[0].selectList var listItemText = list.options[list.selectedIndex].text | |||
Value String. | |||
|
value | NN 4 IE 4 DOM 1 | ||
Read/Write | |||
Value associated with the OPTION element. If the OPTION element has a VALUE attribute or value property set, this is the value returned for the value property; otherwise, the text visible in the list is returned. | |||
Examplevar itemValue = document.forms[0].selectList.options[2]value | |||
Value String. | |||
|