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

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

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

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

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>

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.