Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Form 3.4 | Q200 [ previous next ]

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

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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.