HTML Select tag
<select>
tag creates a drop down list of items.
You have the facility to select more than one items in the dropdown list if the select tag's multiple attribute is present.
The multiple atribute is a boolean attribute which specifies that you can press and hold the ctrl key and click on many items in one go.
The
<select>
tag contains a set of <option>
tags which specify the values of the items in the dropdown box.
By default, the first option that is written inside the select tag is selected. You can change that by specifying anmy other option other than the default option by adding a boolean attribute "selected" to the respective option which you want to be displayed when the select list is not opened.
The name attribute identifies the form element's value for the select element. If you want to enable multiple items to bve selected your name attribute's value should be suffixed by array square brackets. For example:
-
<select name="muliple_test[]" multiple>
-
<select name="single">
-
<option value="volvo">Volvo</option>
Example:
<label for="cars">Choose a car:</label>
<select name="cars" id="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
Sample output:
Comments
Post a Comment