You are here: irt.org | FAQ | JavaScript | Form | 3.4 | Q200 [ previous next ]
There is *always* one option selected in a pull-down menu.
If you include a dummy option at the top of the pull-down menu, like "Select one:", then you can check that the user has selected another one using:
<script language="JavaScript"><!--
function validate(form) {
if (form.selectName.selectedIndex == 0) {
alert('Select one dummy!');
return false;
}
return true;
}
//--></script>
<form onSubmit="return validate(this)">
<select name="selectName">
<option>Select one:
<option>a
<option>b
<option>c
</select>
<input type="submit" value="Submit">
</form>