I am trying to prevent the user from picking the default dropdown menu option. Is there any way to add text instead of value in the dropdown menu option? My code:
<select name='test'>
<option value='default' selected='selected'>Please select the value</option>
<option value='value1'>value1</option>
<option value='value2'>value2</option>
</select>
I don’t want the user to pick ‘Please select the value’ option. Is there better way to to this?
Client side code (javascript/HTML) is OK for this, but it’s only half the battle.
Since you don’t want the user to actually select this “default value”, this is what I would do:
Leve the
valueas an empty string. Then in your server side code, check if the value posted was empty or not. There’s no point in populating an arbitrary default value if you aren’t going to use it.By default, the first
<option>will be selected according to standard browser behavior, so you don’t really need theselectedattribute. You do need thevalue=''though or the browser can post the text content of the<option>.