The <select> Tag
Checkboxes and radio buttons give you
powerful means for creating multiple-choice questions and answers,
but they can lead to long forms that are tedious to write and put a
fair amount of clutter onscreen. The
<select>
tag gives you two compact
alternatives: pull-down menus and scrolling lists.
By placing a
list of <option>
tagged items inside the
<select>
tag of a form, you create a
pull-down menu of choices.
As with other form tags, the
name
attribute is required and used by the browser
when submitting the <select>
choices to the
server. Unlike radio buttons, however, no item is preselected, so if
the user doesn’t select any, no values are sent to
the server when the form is submitted. Otherwise, the browser submits
the selected item or collects multiple selections, each separated
with commas, into a single parameter list and includes the
name
attribute when submitting
<select>
form data to the server.
To allow more than
one option selection at a time, add the multiple
attribute to the <select>
tag. This causes
the <select>
to behave like an
<input type=checkbox>
element. If
multiple
is not specified, exactly one option can
be selected at a time, just like a group of radio buttons.
The size
attribute
determines how many options are visible to the user at one time. The
value of size
should be a positive integer. If
size
is set to 1
and
multiple
is not specified, the
<select>
list is typically implemented as a pop-up menu, while values greater than 1 or specifying ...
Get Webmaster in a Nutshell, Third 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.