HTML form element – Drop down menu

Posted by Shek on May 2, 2008 under HTML | Be the First to Comment | Total View: 689 views

I often like to use drop down menu for the users to input data because it can restrict the choices and can avoid them from making typo mistakes. It is simple to implement and the codes are:

1
2
3
4
5
<select name="select1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>

The codes give:

use the <select></select> to create the drop down menu and use the <option></option> to create a choice.

There is an attribute called value for <option> and it represents the value which will past to the PHP file to process after being submit, please beware that the value and the text can be different.

If you want to set a pre-selected choice when the web page is loaded, attribute “selected” can be use in this case:

1
2
3
4
5
<select name="select1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3" selected="selected">3</option>
</select>

and this will give us:

in the case above, 3 is pre-selected when the web page loads.

Similar Posts:

VN:F [1.9.15_1155]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.15_1155]
Rating: 0 (from 0 votes)

Add A Comment

*