I'm using classic ASP here, and trying to do some Javascript validation.
In my form, I'm dynamically creating checkbox groups - each group has a common Name, and each checkbox has a unique ID. Before the form submits (in the onclick on the submit button) I want to check and make sure each checkbox group has at least one of it's checkboxes checked. If that makes sense :-)
I guess I'm conceptually running into problems. I think I want to, on submit, loop through all of the checkbox Names, and make sure at least one item is checked out of each of those Name groups. Can this be done? This is what I have so far, but I think it's getting thrown off by using the ID instead of the Name:
function validateCheckBox()
{
var checkSelected = false;
var checkboxid
for(i=0; i<document.frmEditCoverages.elements.length; i++)
{
if(document.frmEditCoverages.elements[i].type=="checkbox")
{
/*need to do this for each checkbox on the page*/
checkboxid = document.frmEditCoverages.elements[i];
for (i = 0; i < checkboxid.length; i++){
if (checkboxid[i].checked){
checkSelected = true;
}
}
if (!checkSelected){
alert("WARNING MESSAGE TELLING THEM TO CHECK A CHECKBOX.");
return (false);
}
}
}
}
Any help or advice? Thanks!