option ElementThe option element is declared by the XHTML 1.1 Forms Module
Elements in the Forms Module are:form | label | textarea | select | optgroup | option | button | fieldset | legend | input type="button" | input type="checkbox" | input type="file" | input type="hidden" | input type="image" | input type="password" | input type="radio" | input type="reset" | input type="submit" | input type="text"
An option element
is used to specify an individual choice within a
select
list. When the list is rendered by the browser,
it is the content of the option element
which is displayed to the user.
Its selected
attribute may be specified to state that the option should be pre-selected
within the select list when the form is first rendered. For a
select list without
the multiple
attribute specified, only one of its
option elements may have the
selected
attribute specified.
The value
attribute specifies the value to be sent to the form processor
to represent that option when it is selected.
If a value
attribute is not present, the content of the
option element is used instead.
Here is a very simple select list:
<label for="colour">Colour:</label>
<select id="colour" name="colour">
<option value="1">Black</option>
<option value="2" selected="selected">Red</option>
<option value="3">Blue</option>
</select>
This renders as:
Groups of option elements
may be created within a single
select list
using optgroup
elements.
There are no #REQUIRED attributes on the option element.
option element are listed below:disabled [ type Boolean ]option is initially disabled. The user cannot interact with a disabled control. (Unsupported in IE7 and below for optgroup and option.)label [ type Text ]option element (this attribute is inconsistently supported - e.g. currently Opera uses it but Firefox does not)selected [ type Boolean ]option is pre-selected within the select list, otherwise it is not (this is its initial value - to which it is returned if the form is reset)value [ type CDATA ]option when it is selected - if not present, the contents of the option element are usedoption element are listed below:class [ type NMTOKENS ]id [ type ID ]style [ type CDATA ], from the Style Attribute Module (deprecated)title [ type Text ]xmlns [ type URI - #FIXED 'http://www.w3.org/1999/xhtml' ]dir [ type Enumeration (ltr | rtl) ], from the Bi-directional Text Modulexml:lang [ type LanguageCode ]All attributes in the
Events Attribute Collection
are supported:onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup
option element is:
See Content Model & Nesting for information about Content Model syntax and Nesting Groups.
optionoptionoptgroup, select