Export (0) Print
Expand All
4 out of 6 rated this helpful - Rate this topic

Option object

Creates and initializes a new option element.

Members

The Option object has these types of members:

Methods

The Option object has these methods.

MethodDescription
create

Initializes a new option element. This method cannot be called directly. See Option object.

 

Standards information

There are no standards that apply here.

Remarks

Use this object to instantiate new option elements before adding them to a select element. You can specify up to four optional arguments:

sTextString that specifies the option text.
sValueString that specifies the option value.
bDefaultSelectedBoolean that indicates whether the option is the default selection.
bSelectedBoolean that indicates whether this option is selected when it is added to the collection.

 

Numeric values are coerced into string and Boolean equivalents if possible.

Examples

The following script creates three new option objects and adds them to a select element. Because of the optional arguments, option "Two" is originally selected but option "Three" gains focus when the reset button is pressed.


<form action="#">
<select id="oSelect"></select>
<button type="reset">Reset to Defaults</button>
</form>
<script type="text/javascript">
var sel = document.getElementById('oSelect');
sel.options.add( new Option("One","1") );
sel.options.add( new Option("Two","2",false,true) );
sel.options.add( new Option("Three",3,1,0) );
</script> 

See also

options

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.