The SELECT element defines a selectable list, and the OPTION element is used to define a list item.
<select name="example">
<option value="item1">Item 1</option>
</select>
The OPTION element is placed inside the SELECT element.
The SELECT element
<select name="example" size="3" multiple></select>
Attribute |
Value |
Explanation |
name=" " |
field name |
a unique name for the field |
size=" " |
number |
the number of visible items (the default is 1) |
multiple |
multiple |
multiple items can be selected (HTML : multiple | XHTML : multiple="multiple") |
- name=""
- The field name is used to identify the form field.
- size=""
-
Specifies the number of visible items in the list.
size="1" :
size="3" :
- multiple
-
Multiple items can be selected at a time.
Use the SHIFT or CTRL key to select multiple items.
The OPTION element
<option value="item1" selected>Item 1</option>
Attribute |
Value |
Explanation |
value=" " |
initial value |
this value is submitted |
selected |
selected |
that item is selected (HTML : selected | XHTML : selected="selected") |
- value=""
-
This value is submitted to the server when selected.
<option value="item1">Item 1</option>
If the value attribute is not used, the content of the OPTION element is submitted to the server.
<option>Item 1</option>
- selected
-
That item is selected in the initial state.
Example