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

Q1627 How can I ensure that all the buttons on are form are all clicked before allow the submit button to submit the form?

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

The following adds a clicked property toeach form button as it is clicked. The validate() function then tests each of the form elements making sure that each form element of type button has a clicked property:

<script language="JavaScript"><!--
function validate(form) {
  for (var i=0; i <form.elements.length; i++) {
    if (form.elements[i].type == 'button') {
      if (!form.elements[i].clicked) {
        alert('Click all the buttons first!');
        return false;
      }
    }
  }
  return true;
}
//--></script>

<form onSubmit="return validate(this)">
<input type="button" value="button" onClick="this.clicked=true">
<input type="button" value="button" onClick="this.clicked=true">
<input type="button" value="button" onClick="this.clicked=true">
<input type="button" value="button" onClick="this.clicked=true">
<input type="submit">
</form>

©2018 Martin Webb