Hello all. Below is the routines I am using to validate checkboxes in a form.
there are 9 checkboxes in all. All can be checked.
If number 9 checkbox is checked (Other) then the focus is set to a textfield for an explanation.
Here is the OnSubmit code…
onsubmit=”return checkCheckBoxes(this),checkOther(this);”
the problem is this. Only the last validation command works, which ever is last works.
How can I make them both work?
Thanks
<script type=”text/javascript” language=”JavaScript”>
<!–
function checkCheckBoxes(form) {
if (
form.CHECKBOX_1.checked == false &&
form.CHECKBOX_2.checked == false &&
form.CHECKBOX_3.checked == false &&
form.CHECKBOX_4.checked == false &&
form.CHECKBOX_5.checked == false &&
form.CHECKBOX_6.checked == false &&
form.CHECKBOX_7.checked == false &&
form.CHECKBOX_8.checked == false &&
form.CHECKBOX_9.checked == false)
{
alert (‘You must check a box!’);
return false;
} else {
return true;
}
}
function checkOther(form) {
if (form.CHECKBOX_9.checked) {
if (form.ExplainOther.value.length > 0) {
return true;
}
else {
alert (“Please explain your Other selection.”);
form.ExplainOther.focus();
return false;
}
}
else {
return false;
}
}
// End –>
</script>