Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q200 How do you check that a selection in an options list has been selected?

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>

Feedback on 'Q200 How do you check that a selection in an options list has been selected?'

©2018 Martin Webb