Form Validation Help
I'm about to scratch my eyeballs out so I hope someone can help me. I'm sure I'm making a stupid mistake but I can't figure it out. I've got a form and part of it is a series of checkboxes. I want to validate the checkboxes to make sure at least one is selected before the form is processed. All the other elements are validating fine (pull down menus, radio buttons) but I can't get the checkboxes to work for the life of me.
Here is part of what I have in the script tag. The first two "if" statments work. The third statemnt where I refer to the element "product" is where it is messing up.
If I leave the checkbox validation part off, everything else works fine. However if I include the checkbox validation the first 2 will work and then the form will submit and will ignore everything after the checkbox validation.
In the HTML tags, each checkbox has the name "product" and each has a different value.
I hope all of that makes sense. Thanks!
Here is part of what I have in the script tag. The first two "if" statments work. The third statemnt where I refer to the element "product" is where it is messing up.
function check()
{
if(document.forms.BOLForm.EmailAddress.selectedIndex == 0)
{
alert("Please choose your name from the drop-down menu."); //alert with appropriate message
return false;
}
if(!document.forms.BOLForm.FirstOption[0].checked && !document.forms.BOLForm.FirstOption[1].checked){
alert("Please choose whether this is an Add or Renew submission");
return false;
}
if(!document.forms.BOLForm.product[0].checked && !document.forms.BOLForm.product[1].checked && !document.forms.BOLForm.product[2].checked && !document.forms.BOLForm.product[3].checked && !document.forms.BOLForm.product[4].checked && !document.forms.BOLForm.product[5].checked && !document.forms.BOLForm.product[6].checked && !document.forms.BOLForm.product[7].checked && !document.forms.BOLForm.product[8].checked)
{
alert("Please choose the product you are inquiring about.");
return false;
}
if(document.forms.BOLForm.Type.selectedIndex == 0)
{
alert("Please select the Type of institution"); //alert with appropriate message
return false;
}
if(document.forms.BOLForm.Consortium.selectedIndex == 0)
{
alert("Please select the Consortium name"); //alert with appropriate message
return false;
}
if(document.forms.BOLForm.Month.selectedIndex == 0)
{
alert("You must enter an expiration date"); //alert with appropriate message
return false;
}
if(document.forms.BOLForm.Day.selectedIndex == 0)
{
alert("You must enter an expiration date"); //alert with appropriate message
return false;
}
if(document.forms.BOLForm.Year.selectedIndex == 0)
{
alert("You must enter an expiration date"); //alert with appropriate message
return false;
}
if(document.forms.BOLForm.InstitutionName.value == "")
{
alert("Please enter an Institution Name"); //alert with appropriate message
return false;
}
document.forms.BOLForm.AutoresponseAddress.value = document.forms.BOLForm.EmailAddress[document.forms.BOLForm.EmailAddress.selectedIndex].value;
document.forms.BOLForm.Submit.disabled = true;
}
If I leave the checkbox validation part off, everything else works fine. However if I include the checkbox validation the first 2 will work and then the form will submit and will ignore everything after the checkbox validation.
In the HTML tags, each checkbox has the name "product" and each has a different value.
I hope all of that makes sense. Thanks!
