I have done this before, but for some reason it doesn't want to work with my if statements...it keeps submitting the form when nothing is filled out.
It's the validation for an html form, and there are checkboxes that display certain parts of the form. If a checkbox is checked, it needs to validate the fields within that section. type1 through type6 are the checboxes.
If I take all of the code away after the type1 if statement, it works fine. If I add it back, it starts submitting the form when it's not filled out.
If you can help me out, I'd be so grateful!
<script type="text/javascript">
function validate_form() {
if(document.contactform.firstname.value == '') {
alert('Please enter your First Name.');
return false;
}
if(document.contactform.lastname.value == '') {
alert('Please enter your Last Name.');
return false;
}
if(document.contactform.company.value == '') {
alert('Please enter your Company.');
return false;
}
if(document.contactform.address.value == '') {
alert('Please enter your address.');
return false;
}
if(document.contactform.city.value == '') {
alert('Please enter your city.');
return false;
}
if(document.contactform.state.value == '') {
alert('Please enter your state.');
return false;
}
if(document.contactform.zipcode.value == '') {
alert('Please enter your zipcode.');
return false;
}
if(document.contactform.country.value == '') {
alert('Please enter your country.');
return false;
}
if(document.contactform.workphone.value == '') {
alert('Please enter your work phone.');
return false;
}
if(document.contactform.email.value == '') {
alert('Please enter your email.');
return false;
}
if(document.contactform.website.value == '') {
alert('Please enter your website.');
return false;
}
if(document.contactform.type1.value) {
if((document.contactform.prefcontactcs[0].checked == false) && (document.contactform.prefcontactcs[1].checked == false)) {
alert('Please enter your Contact Preference for Customer Support.');
return false;
}
if((document.contactform.timecontactcs[0].checked == false) && (document.contactform.timecontactcs[1].checked == false)) {
alert('Please enter your Contact Time Preference for Customer Support.');
return false;
}
return false;
}
if(document.contactform.type2.value) {
if(document.contactform.organicmaterial.value == '') {
alert('Please enter the type of organic material.');
return false;
}
if((document.contactform.prefcontactps[0].checked == false) && (document.contactform.prefcontactps[[1].checked == false)) {
alert('Please enter your Contact Preference for Project Information.');
return false;
}
if((document.contactform.timecontactps[0].checked == false) && (document.contactform.timecontactps[1].checked == false)) {
alert('Please enter your Contact Time Preference for Project Information.');
return false;
}
return false;
}
if(document.contactform.type3.value) {
if((document.contactform.prefcontactpi[0].checked == false) && (document.contactform.prefcontactpi[1].checked == false)) {
alert('Please enter your Contact Preference for Product Information.');
return false;
}
if((document.contactform.timecontactpi[0].checked == false) && (document.contactform.timecontactpi[1].checked == false)) {
alert('Please enter your Contact Time Preference for Product Information.');
return false;
}
return false;
}
if(document.contactform.type4.value) {
if(document.contactform.modelnum.value == '') {
alert('Please enter the model number.');
return false;
}
if(document.contactform.serialnum.value == '') {
alert('Please enter the serial number.');
return false;
}
if(document.contactform.purchasedate.value == '') {
alert('Please enter the purchase date.');
return false;
}
if(document.contactform.locationinstall.value == '') {
alert('Please enter the install location.');
return false;
}
if(document.contactform.usage.value == '') {
alert('Please enter the machine usage.');
return false;
}
if(document.contactform.wasterecycled.value == '') {
alert('Please enter the type of organic waste recycled.');
return false;
}
if((document.contactform.companytype[0].checked == false) && (document.contactform.companytype[1].checked == false) && (document.contactform.companytype[2].checked == false) && (document.contactform.companytype[3].checked == false) && (document.contactform.companytype[4].checked == false) && (document.contactform.companytype[5].checked == false) && (document.contactform.companytype[6].checked == false) && (document.contactform.companytype[7].checked == false)) {
alert('Please enter the company type.');
return false;
}
if(document.contactform.contactperson.value == '') {
alert('Please enter the contactperson.');
return false;
}
if((document.contactform.prefcontactts[0].checked == false) && (document.contactform.prefcontactts[[1].checked == false)) {
alert('Please enter your Contact Preference for Technical Support.');
return false;
}
if((document.contactform.timecontactts[0].checked == false) && (document.contactform.timecontactts[1].checked == false)) {
alert('Please enter your Contact Time Preference for Technical Support.');
return false;
}
return false;
}
if(document.contactform.type5.value) {
if(document.contactform.salesposition.value == '') {
alert('Please enter the area of interest.');
return false;
}
if(document.contactform.salesregion.value == '') {
alert('Please enter the desired region.');
return false;
}
if(document.contactform.experienceselling.value == '') {
alert('Please enter your experience selling recycling equipment.');
return false;
}
if(document.contactform.productinterest.value == '') {
alert('Please enter the GaiaRecycle product interest.');
return false;
}
if((document.contactform.prefcontactso[0].checked == false) && (document.contactform.prefcontactso[[1].checked == false)) {
alert('Please enter your Contact Preference for Sales/Referral Opportunities.');
return false;
}
if((document.contactform.timecontactso[0].checked == false) && (document.contactform.timecontactso[1].checked == false)) {
alert('Please enter your Contact Time Preference for Sales/Referral Opportunities.');
return false;
}
return false;
}
if(document.contactform.type6.value) {
if((document.contactform.prefcontactoi[0].checked == false) && (document.contactform.prefcontactoi[1].checked == false)) {
alert('Please enter your Contact Preference for Other Information.');
return false;
}
if((document.contactform.timecontactoi[0].checked == false) && (document.contactform.timecontactoi[1].checked == false)) {
alert('Please enter your Contact Time Preference for Other Information.');
return false;
}
return false;
}
}
</script>