|
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>
|
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.