DOM Objects
DOM Anchor
DOM Applet
DOM Area
DOM Base
DOM Basefont
DOM Body
DOM Button
DOM Checkbox
DOM Document
DOM Event
DOM FileUpload
DOM Form
DOM Frame
DOM Frameset
DOM Hidden
DOM History
DOM Iframe
DOM Image
DOM Link
DOM Location
DOM Meta
DOM Navigator
DOM Option
DOM Password
DOM Radio
DOM Reset
DOM Screen
DOM Select
DOM Style
DOM Submit
DOM Table
DOM TableData
DOM TableHeader
DOM TableRow
DOM Text
DOM Textarea
DOM Window

Option Object

For each instance of an HTML <option> tag in a selection list on a form, an Option object is created.

An option in a selection list can be created either with the HTML <option> tag:

<option>Wolksvagen</option>

OR by using the option constructor and assign it to an index of the relevant Select object:

document.myForm.cartypes[3]=new Option("Wolksvagen")

Tip: Refresh the document by using history.go(0) at the end of the code to make the new option visible.

To specify a value to be returned to the server when an option is selected and the form submitted:

document.myForm.cartypes[3]=new Option("Wolksvagen","WV")

To make the option selected by default in the selection list:

document.myForm.cartypes[3]=new Option("Wolksvagen","WV",true)

The Option object's properties and methods are described below:

N: Netscape (including Mozilla when N6 or higher), IE: Internet Explorer, W3C: World Wide Web Consortium (Internet Standard)

Properties

Syntax: object.property_name

Property Description N IE  W3C
defaultSelected Sets or returns the value of the selected attribute of the option 6 3.02 Yes
disabled Sets or returns a Boolean value that specifies whether the option should be disabled 6 5.5 Yes
form Returns a reference to the form that contains the option object 6 3.02 Yes
id Sets or returns the id of the option (In IE 4 this property is read-only)   4 No
index Sets or returns the position of the option in the select box   3.02 Yes
label Sets or returns a label for the option object   6 Yes
selected Sets or returns the current state of the option 6 3.02 Yes
text Sets or returns the text value for the <option> tag 6 3.02 Yes
value

Sets or returns the value to be returned to the server when an option is selected and the form is submitted

6 3.02 Yes

Methods

Syntax: object.method_name()

Method Description N IE W3C
click() Simulates a mouse-click on the option   4 No