Working with Lists
A list displays a number of options from which the visitor can choose, as in Figure 68.5. Lists are better than radio buttons or checkboxes if the number of options is rather large, since lists make better use of space.The size attribute of the list's select tag determines how many options are visible at once. If the list contains more options than this number, the browser adds a scrollbar to the right side of the list.
Listing 68.6. View Source for Figure 68.6.
<form>
<table>
<tr>
<td>Select the newsletter you would like to receive:</td>
</tr>
<tr>
<td><select name="newsletterList" size="5">
<option value="news">News</option>
<option value="sports">Sports</option>
<option value="business">Business</option>
<option value="entertainment">Entertainment</option>
<option value="humor">Humor</option>
<option value="style">Style</option>
<option value="travel">Travel</option>
<option value="science">Science</option>
<option value="culture">Culture</option>
</select></td>
</tr>
</table>
</form>
Figure 68.6. Organize a large number of choices in a list.
[View full size image]
To allow your visitors to select more than one item from the list, add the multiple attribute to the select tag:
newsletterList=culture
<select name="newsletterList" size="5" multiple>
|
If you designed your list to accept multiple options, you may have multiple preselected options:
<option value="news" selected>News</option>
Otherwise, the browser takes one preselected option and ignores the others. Internet Explorer defaults to the first selected option, while Netscape defaults to the last.
<option value="news" selected>News</option>
<option value="sports" selected>Sports</option>
<option value="business" selected>Business</option>