PHPSuperBlog.com

HTML form element – Drop down menu

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

<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:

<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.

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Similar Posts:

Leave a comment