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>