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

Q1666 How can I ensure that a user has checked button, and has selected an item from a select list?

You are here: irt.org | FAQ | JavaScript | Form | Q1666 [ previous next ]

Try something like:

<script language="JavaScript"><!--
function formvalidate(request){
  if (!request.choice[0].checked  && !request.choice[1].checked && !request.choice[2].checked) {
    alert('You must select one of the 3 choices to submit this request.');
    return false;
  }

  if (request.selectName[request.selectName.selectedIndex].value == '') {
    alert('You must select one of the options.');
    return false;
  }

  return true;
}
//--></script>

<form onSubmit="return formvalidate(this)">
<input type="radio" name="choice" value="1">
<input type="radio" name="choice" value="2">
<input type="radio" name="choice" value="3">
<select name="selectName">
<option value="">Select One:
<option value="1">1
<option value="2">2
<option value="3">3
</select>
<input type="submit">
</form>

©2018 Martin Webb