Option Tag
The option tag is used with the <select> tag (the select tag will be discussed immediately after this) to create select lists. It indicates the start of a new option in the list. It is used with the value attribute which indicates what is sent to the server. The text that follows the option tag is the text that is displayed in the browser. In HTML the <option> tag need not be closed but it has to be done in XHTML. This is the only difference between the option tag of HTML and option tag of XHTML.
Attribute of Option Tag
Value
It indicates the value that is sent to the server when that option is selected. The user does not see the value of value attribute in the browser.
| Example |
<select name=”jokenumber”> |
<option value=”001”> Cricket jokes </option> |
<option value=”002”> Golf jokes </option> |
<option value=”003”> Tennis jokes </option> |
</select> |
| |
Select Tag
The select tag creates a list of options, one or more of which can be selected. In its simplest form, it has a <select> tag, one or more <option> tags and a </select> tag. It is exactly similar to the <select> tag of HTML.
| Example |
<select name=”jokenumber”> |
<option value=”001”> Cricket jokes </option> |
<option value=”002”> Golf jokes </option> |
<option value=”003”> Tennis jokes </option> |
</select> |
| |
| |
Attributes of Select Tag
Name
This names the select field for use with the server. It works similarly as it works with the input tag.
| Example |
<select name=”jokenumber”> |
|
</select> |
| |
Size
Size indicates how many rows of the list should be displayed. It means the number of items that are shown in the drop down list. The default size is one.
| Example |
<select name=”jokenumber” size=4 > |
|
</select> |
| |
Multiple
Multiple indicates that more than one option from the list can be selected. It is useful to apply the size attribute while creating multiple lists.
Example: |
|
<select name=”jokenumber” multiple size=4> |
|
</select> |
| |
Optgroup Tag
The Optgroup tag defines an option group. Various choices can be grouped under this tag. When there is a long list of options, groups of related choices are easier to handle. These groups are user friendly and timesaving. This tag is the same as used in HTML.
Attribute of Optgroup
Label
It defines a label for the option field.
Example |
<select name=”jokenumber”> |
<optgroup label=”Game jokes”> |
<option value=”001”> Cricket jokes </option> |
<option value=”002”> Golf jokes </option> |
</optgroup> |
|
<optgroup label=”Other jokes”> |
<option value=”111”> Classic jokes </option> |
<option value=”112”> Short jokes </option> |
</optgroup> |
</select> |
| |
|