Sean@WMS
Oct 30th 2008, 6:02 pm
I have a form I'm working on with a series of checkboxes, reg0 through reg11, that I'm trying to validate to make sure at least one was checked. However, there are other checkboxes on the form, so I can't just simply count up all of the checkboxes -- I need to check against this specific set of them.
Here's what I've tried:
// Check to make sure at least one workshop was selected
var checkbox_choices = 0;
for (counter = 0; counter < 11; counter++)
{
if (form.reg[counter].checked)
{ checkbox_choices = checkbox_choices + 1; }
}
if (checkbox_choices < 1 )
{
alert("Please select at least one workshop." + checkbox_choices);
form.reg0.focus();
return (false);
}
I also tried if (form.reg+counter.checked), and that had the curious effect of not erroring, but not counting checkbox_choices either, so it always throws the alert and returns false.
Here's what I've tried:
// Check to make sure at least one workshop was selected
var checkbox_choices = 0;
for (counter = 0; counter < 11; counter++)
{
if (form.reg[counter].checked)
{ checkbox_choices = checkbox_choices + 1; }
}
if (checkbox_choices < 1 )
{
alert("Please select at least one workshop." + checkbox_choices);
form.reg0.focus();
return (false);
}
I also tried if (form.reg+counter.checked), and that had the curious effect of not erroring, but not counting checkbox_choices either, so it always throws the alert and returns false.