Learning HTML 3.2 by Examples, section 5 Descriptions of HTML 3.2 tags:

SELECT - menu in a form

Purpose

To specify, within a form, a menu from which the user can select one or more alternatives. Effectively, a SELECT element defined a form field where user's input is restricted to an enumerated list of values.

Typical rendering

A selection menu which can be "activated" in some browser-dependent way; in a typical graphical browser this means a pull-down menu. Depending on the browser and on the element, all alternatives may be visible at the same time or the user may need to scan through the list one at a time.

Basic syntax

<SELECT NAME=name>
OPTION elements
</SELECT>

Possible attributes

attribute name possible values meaning notes
NAME string a property name that is used to identify the menu choice when the form is submitted to the server obligatory; each selected option results in a name/value pair being included as part of the contents of the form
SIZE integer sets the number of visible choices applicable when MULTIPLE is set
MULTIPLE MULTIPLE signifies that the user can make multiple selections from the menu by default only one selection is allowed

Allowed context

Text container, i.e. any element that may contain text elements. This includes most HTML elements. However, the text container must appear within a FORM element.

Contents

OPTION elements.

Examples

Example:

    <SELECT NAME="flavor">
    <OPTION VALUE=a SELECTED>Vanilla
    <OPTION VALUE=b>Strawberry
    <OPTION VALUE=c>Rum and Raisin
    <OPTION VALUE=d>Peach and Orange
    </SELECT>

Notes

See the description of the FORM element, which contains some examples of entire forms.

As an alternative to SELECT, you may wish to consider using a set of INPUT elements with TYPE=CHECKBOX or TYPE=RADIO, typically resulting in a rendering which allows the user see all alternatives at a glance.

You should always provide a default choice (an OPTION element with attribute SELECTED set) within a SELECT element. For reasons to this, see my document Choices in HTML forms.



Date of last update: 2010-12-16.
This page belongs to the free information site IT and communication, section Web authoring and surfing, by Jukka "Yucca" Korpela.