I created a web form with some validation in the JS Header which works well.
However, there are six checkboxes on the form. One of the checkboxes has to be checked by the customer. If at least one is checked, the form is validated to that point, and other validation can take place.
If at least one checkbox is NOT checked, I’ll display a dialog with error information and return them to the form so they can finish their input.
How do I check to see if none of the boxes have been checked?
I’m a real javascript novice, but if someone can point me in the right direction, it will help.
Thanks in advance
Subject: JS Header and validation (once more)
for (i=0;i<document.forms[0].checkboxname.length;i++){ x=“”;
if(document.forms[0].checkboxname[i].checked){
x = document.forms[0].checkboxname[i].value;
break;
}
}
if(x== ""){
alert("Select checkboxname");
return;
}
HTH
Keshava
Subject: RE: JS Header and validation (once more)
Keshava -
Thanks for the response. Since my checkboxes don’t have similar names, I don’t think I can use the code (although I certainly tried!). I did work out some validation which worked though. All I needed was to have ONE checkbox checked to validate the form. If none were checked, the alert dialog would display and then take the customer back to the form to finish filling it out.
Here’s what I came up with, which does work. Thanks to the JavaScript Bible and your suggestion:
var f = document.forms[0]
if (f.WillAttend.checked==false && f.NotCitizen.checked==false && f.NotResident.checked==false && f.HaveServed.checked==false && f.Over70.checked==false && f.DeferDuty.checked==false)
{
alert(“You must choose a checkbox option.”);
return false;
}
Thanks again!
Bruce