Sams Teach Yourself HTML 4 in 24 Hours

Sams Teach Yourself HTML 4 in 24 Hours

By Dick Oliver

Selection Lists

Both scrolling lists and pull-down pick lists are created with the <select> tag. You use this tag together with the <option> tag:

<select name="extras" size="3" multiple>
<option selected> Electric windows</option>
<option> AM/FM Radio</option>
<option> Turbocharger</option>
</select>

No HTML tags other than <option> and </option> should appear between the <select> and </select> tags.

Unlike the text input type, the size attribute here determines how many items show at once on the selection list. If size="2" were used in the preceding code, only the first two options would be visible, and a scrollbar would appear next to the list so the user could scroll down to see the third option.

Including the multiple attribute allows users to select more than one option at a time, and the selected attribute makes an option selected by default. The actual text that accompanies selected options is returned when the form is submitted. If the user selected Electric windows and Turbocharger, for instance, the form results would include the following lines:

extras=Electric windows
extras=Turbocharger

(As I cautioned you earlier with regard to the checked attribute, the new XHTML standard will eventually require you to use multiple="multiple" and selected="selected". For now you should continue to use just multiple and selected for maximum compatibility with current browsers.)

Share ThisShare This

Informit Network