HTML Form Lists
Using Lists in Forms - the <select> Tag
Sometimes you want to have a user choose from many options using one control. To do this you can use the select tag.
Examples for <select>
<select name="fruitselect">
<option>apples</option>
<option>oranges</option>
<option>grapes</option>
<option>kiwi</option>
</select>Give it a go!
<select name="fruitselect">
<option value="apples">apples</option>
<option>oranges</option>
<option>grapes</option>
<option>kiwi</option>
</select>Give it a go!
<select name="fruitselect" size="3" multiple>
<option value="apples">apples</option>
<option>oranges</option>
<option selected>grapes</option>
<option>kiwi</option>
</select>Give it a go!
The server side script used in the above examples for give it a go is this:
<?php
echo $_POST['fruitselect'];
?>
Attributes for <select>
| multiple |
multiple |
Allows multiple items to be selected from the list. |
| size |
a number |
Specify the number of visible rows. |
| tabindex |
a number |
Specify the tab index of the list. In forms use the tab index to specify the order of the controls the focus moves to when the user clicks the tab key. |
Attributes for <option>
| selected |
selected |
Specifies the option is selected. Will highlight the option in the list |
| value |
text |
Specifies the an alternative value of the option to send to the server. If this attribute is not specified the value of the option will be its contents. |