AvailabilityJavaScript 1.0; enhanced in JavaScript 1.1 Inherits from/OverridesInherits from HTMLElement Synopsisselect.options[i] ConstructorIn JavaScript 1.1, Option objects can be dynamically created with the Option( ) constructor, as follows: new Option(text, value, defaultSelected, selected) Arguments
PropertiesOption inherits the properties of HTMLElement and defines the following:
In JavaScript 1.0, the text property is read-only. In JavaScript 1.1, it is read/write. By setting a new value for this property, you can change the text that appears for the option within its Select object. Note that if you plan to set this property in a browser that cannot reflow document content, you should ensure that changing the option label does not make the Select object wider. If the object must become wider, ensure that no information to the right of the Select object becomes obscured when it grows.
HTML SyntaxAn Option object is created by an <option> tag within a <select>, which is within a <form>. Multiple <option> tags typically appear within the <select>: <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> DescriptionThe 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 of the <option> tag, it must be plain, unformatted text without any HTML tags so it can be properly displayed in list boxes and drop-down menus that do not support HTML formatting. In JavaScript 1.1, 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 s by assigning it to: s.options[options.length] See the Select.options[] reference page for details. See AlsoSelect, Select.options[]; HTMLOptionElement and HTMLSelectElement in the DOM reference section |