Section 25.224. Option: an option in a Select element


25.224. Option: an option in a Select element

DOM Level 2 HTML: Node Element HTMLElement HTMLOptionElement

25.224.1. Constructor

Option objects can be created with Document.createElement( ), like any other tag. In the DOM Level 0, Option objects can also be dynamically created with the Option( ) constructor, as follows:

 new Option(String text, String value,            boolean defaultSelected, boolean selected) 

25.224.2. 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.

25.224.3. Properties


boolean defaultSelected

The initial value of the selected attribute of the <option> element. If the form is reset, the selected property is reset to the value of this property. Setting this property also sets the value of the selected property.


boolean disabled

If TRue, this <option> element is disabled, and the user is not allowed to select it. Mirrors the disabled attribute.


readonlyHTMLFormElementform

A reference to the <form> element that contains this element.


readonly long index

The position of this <option> element within the <select> element that contains it.


String label

The text to be displayed for the option. Mirrors the label attribute. If this property is not specified, the plain-text content of the <option> element is used instead.


boolean selected

The current state of this option: if true, the option is selected. The initial value of this property comes from the selected attribute.


readonly String text

The plain text contained within the <option> element. This text appears as the label for the option.


String value

The value submitted with the form if this option is selected when form submission occurs. Mirrors the value attribute.

25.224.4. HTML Syntax

An Option object is created by an <option> tag within a <select> tag, which is within a <form>. Multiple <option> tags typically appear within the <select> tag:

 < form ...> < select  ...> < option   [ value="value" ]  // The value returned when the form is submitted   [ selected ] >      // Specifies whether this option is initially selected    plain_text_label  // The text to display for this option [ < /option>  ]   ... < /select>   ... /form> 

25.224.5. Description

The Option object describes a single option displayed within a Select object. The properties of this object specify whether it is selected by default, whether it is currently selected, the position it has in the options[] array of its containing Select object, the text it displays, and the value it passes to the server if it is selected when the containing form is submitted.

Note that although the text displayed by this option is specified outside the <option> tag, it must be plain, unformatted text without any HTML tags so it can be properly displayed in listboxes and drop-down menus that do not support HTML formatting.

You can dynamically create new Option objects for display in a Select object with the Option( ) constructor. Once a new Option object is created, it can be appended to the list of options in a Select object with Select.add( ). See Select.options[] for further details.

25.224.6. See Also

Select, Select.options[]; Chapter 18




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net