Name

Option — an option in a Select box

Availability

JavaScript 1.0; enhanced in JavaScript 1.1

Inherits from/Overrides

Inherits from HTMLElement

Synopsis

                  select.options[i]

Constructor

In JavaScript 1.1, Option objects can be dynamically created with the Option( ) constructor, as follows:

new Option(text, value, defaultSelected, selected)

Arguments

text

An optional string argument that specifies the text property of the Option object.

value

An optional string argument that specifies the value property of the Option object.

defaultSelected

An optional boolean argument that specifies the defaultSelected property of the Option object.

selected

An optional boolean argument that specifies the selected property of the Option object.

Properties

Option inherits the properties of HTMLElement and defines the following:

defaultSelected

A boolean that specifies whether the option is initially selected when the Select object that contains it is created. This value is used to restore a Select object to its initial state when the containing form is reset. The initial value of this property is specified by the selected attribute of the <option> tag.

index

A read-only integer that specifies the position or index of the option within the options[] array of the Select object that contains it. The first Option object in the array has its index property set to 0. The second Option has an index of 1, and so on.

selected

A read/write boolean value that specifies whether an option is currently selected. ...

Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.