Name

Select — a graphical selection list

Inherits from

Node, Element, FormControl

Synopsis

The Select element represents an HTML <select> tag, which displays a graphical list of choices to the user. If the HTML multiple attribute is present, the user may select any number of options from the list. If that attribute is not present, the user may select only one option, and options have a radio button behavior—selecting one deselects whichever was previously selected.

The options in a Select element can be displayed in two distinct ways. If the size attribute has a value greater than 1, or if the multiple attribute is present, they are displayed in a list box that is size lines high in the browser window. If size is smaller than the number of options, the listbox includes a scrollbar. On the other hand, if size is 1 and multiple is not specified, the currently selected option is displayed on a single line, and the list of other options is made available through a drop-down menu. The first presentation style displays the options clearly but requires more space in the browser window. The second style requires minimal space but does not display alternative options as explicitly. size defaults to 4 when the multiple attribute is set, and 1 otherwise.

The options[] property of the Select element is the most interesting. This is an array-like object of <option> elements (see Option) that describe the choices presented by the Select element. For historical reasons, this array-like object has some ...

Get JavaScript: The Definitive Guide, 6th 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.