select tag (XHTML 1.1)
option selectorThe select element allows the user to select between a pre-defined range of elements. It comes in two different forms: A dropdown list or a listbox. This behavior is controlled by the multiple attribute, as described below. Here's an example of the select element, rendered as a dropdown list:
Each element in the select box is generated by using an option tag, like this:
<select name="Persons">
<option>Select person...</option>
<option>John Doe</option>
<option>Jane Doe</option>
</select>
The multiple attribute
A standard select list only allows the selection of one option, but what if we wanted our user to be able to select more than one? That's exactly what the boolean multiple attribute is for. Here's an example:
<select name="Persons" multiple="multiple">
<option>Anyone</option>
<option>John Doe</option>
<option>Jane Doe</option>
</select>
The result will look like this:
Select one item by clicking it, and more items by holding down the <Ctrl> or <Shift> key on your keyboard while clicking.
Attributes
| Attribute | Deprecated | Required | Description |
|---|---|---|---|
| class | space-separated list of classes | ||
| dir | direction for weak/neutral text | ||
| disabled | unavailable in this context | ||
| id | document-wide unique id | ||
| lang | language code | ||
| multiple | default is single selection | ||
| name | field name | ||
| size | rows visible | ||
| style | associated style info | ||
| tabindex | position in tabbing order | ||
| title | advisory title |
Events
| Event | Description |
|---|---|
| onblur | the element lost the focus |
| onchange | the element value was changed |
| onclick | a pointer button was clicked |
| ondblclick | a pointer button was double clicked |
| onfocus | the element got the focus |
| onkeydown | a key was pressed down |
| onkeypress | a key was pressed and released |
| onkeyup | a key was released |
| onmousedown | a pointer button was pressed down |
| onmousemove | a pointer was moved within |
| onmouseout | a pointer was moved away |
| onmouseover | a pointer was moved onto |
| onmouseup | a pointer button was released |
© htmlpedia.net 2008 - 2012