Link to home
Start Free TrialLog in
Avatar of Jonathan Greenberg
Jonathan GreenbergFlag for United States of America

asked on

What is preventing my JS from working?

I have a page of JavaScript (code is below) that is used on an insurance company Web site to validate form data and calculate the amount to be charged, which is then returned to my Web form.

Until today, it required that the user select a coverage time period of a minimum of 3 weeks. The script worked perfectly.

Two hours ago, someone on EE modified the code for me so that it now requires a minimum period of 3 months, instead of 3 weeks. This function works flawlessly. But the new code, while it still validates correctly, has stopped the script from returning to my Web form a calculation of the amount to be charged.

Below is the original JavaScript, which works, followed by the new JavaScript, which doesn't work. Almost all of the changed code is lines 39-57 in the old JavaScript, and lines 39-87 in the new JavaScript.

What is missing or has been added in the new JavaScript that's preventing it from returning a value to my Web page? Thanks.
<!-- Old, working JavaScript -->
 
function addDays() {
	var efday = document.enrollForm.effectiveDay.selectedIndex;
	var efmon = document.enrollForm.effectiveMonth.selectedIndex;
	var efyr = document.enrollForm.effectiveYear.selectedIndex;
	var termon = document.enrollForm.terminationMonth.selectedIndex;
	var terday = document.enrollForm.terminationDay.selectedIndex;
	var teryr = document.enrollForm.terminationYear.selectedIndex;
	var curmon = efmon;
	var curyr = efyr;
	var totalDays = 0;
	var numWeeks = 0;
	
	var daysInMonth = new Array(12);
	daysInMonth[1] = 31;
	daysInMonth[2] = 28;
	daysInMonth[3] = 31;
	daysInMonth[4] = 30;
	daysInMonth[5] = 31;
	daysInMonth[6] = 30;
	daysInMonth[7] = 31;
	daysInMonth[8] = 31;
	daysInMonth[9] = 30;
	daysInMonth[10] = 31;
	daysInMonth[11] = 30;
	daysInMonth[12] = 31;
 
	if (efday > daysInMonth[efmon]) {
		alert("The effective date you chose does not exist");
		return 1000;
	}
 
	if (terday > daysInMonth[termon]) {
		alert("The termination date you chose does not exist");
		return 1000;
	}
 
	if (teryr == efyr) {
		if (termon == efmon) {
			totalDays = (terday - efday) + 1;
		}
		else {
			totalDays = (daysInMonth[efmon] - efday) + 1;
		}
	}
	else {
			totalDays += (daysInMonth[efmon] - efday) + 1;
	}
	curmon += 1;
 
	if (teryr != efyr) {
		while (curmon <= 12) {
			totalDays += daysInMonth[curmon];
			curmon += 1;
		}
		curmon = 1;
		while (curmon <= termon) {
			if (curmon == termon) {
				totalDays += terday;
			}
			else {
				totalDays += daysInMonth[curmon];
			}
			curmon += 1;
		}
	}
	else {
		if (termon != efmon) {
			while (curmon <= termon) {
				if (curmon == termon) {
					totalDays += terday;
				}
				else {
					totalDays += daysInMonth[curmon];
				}
			curmon += 1;
			}
		}
	}
	numweeks = Math.floor(eval(totalDays/7));
 
	if ((totalDays%7) > 1) {
		numweeks += 1;
	}
 
	return numweeks;
	
}
 
function getTotal() {
 
	var prem = 0;
	var spouse = 0;
	var sRate = 60;
	var child = 0;
	var chPrem = 0;
	var totalRate = 0;
	var totalPrem = 0;
	var insage = document.enrollForm.student_Age.selectedIndex;
	
	var effday = document.enrollForm.effectiveDay.selectedIndex;
	var effmon = document.enrollForm.effectiveMonth.selectedIndex;
	var effyr = document.enrollForm.effectiveYear.selectedIndex;
	var termmon = document.enrollForm.terminationMonth.selectedIndex;
	var termday = document.enrollForm.terminationDay.selectedIndex;
	var termyr = document.enrollForm.terminationYear.selectedIndex;
	
	if (insage == 0) {
		alert("Please select age");
		document.enrollForm.student_Age.focus();	
	}
	if (insage == 1) {
		prem = 15;
	}
	if (insage == 2) {
		prem = 18;
	}
	if (insage == 3) {
		prem = 34;
	}
	if ((effday==0) || (effmon==0) || (effyr==0)) {
		alert("Please select desired effective date");
		document.enrollForm.effectiveMonth.focus();
		return false;	
	}
	if ((termday==0) || (termmon==0) || (termyr==0)) {
		alert("Please select desired termination date");
		document.enrollForm.terminationMonth.focus();
		return false;	
	}
	if (effyr>termyr) {
		alert("Termination date must be after Effective date");
		return false;
	}
	if (effyr==termyr) {
		if (effmon>termmon) {
			alert("Termination date must be after Effective date");
			return false;
		}
		if ((effmon==termmon) && (effday>termday)) {
			alert("Termination date must be after Effective date");
			return false;
		}
	}
 
	if (document.enrollForm.spouse_DOB.value != "" && document.enrollForm.spouse_Name.value == "") {
		alert("Please enter your spouse's name");
		document.enrollForm.spouse_Name.focus();
		return false;
	}
	if (document.enrollForm.child1_DOB.value != "" && document.enrollForm.child1_Name.value == "") {
		alert("Please enter your child's name");
		document.enrollForm.child1_Name.focus();
		return false;
	}
	if (document.enrollForm.child2_DOB.value != "" && document.enrollForm.child2_Name.value == "") {
		alert("Please enter your child's name");
		document.enrollForm.child2_Name.focus();
		return false;
	}
	if (document.enrollForm.child3_DOB.value != "" && document.enrollForm.child3_Name.value == "") {
		alert("Please enter your child's name");
		document.enrollForm.child3_Name.focus();
		return false;
	}
	if (document.enrollForm.spouse_Name.value != "" && document.enrollForm.spouse_DOB.value == "") {
		alert("Please enter your spouse's date of birth");
		document.enrollForm.spouse_DOB.focus();
		return false;
	}
	if (document.enrollForm.child1_Name.value != "" && document.enrollForm.child1_DOB.value == "") {
		alert("Please enter your child's date of birth");
		document.enrollForm.child1_DOB.focus();
		return false;
	}
	if (document.enrollForm.child2_Name.value != "" && document.enrollForm.child2_DOB.value == "") {
		alert("Please enter your child's date of birth");
		document.enrollForm.child2_DOB.focus();
		return false;
	}
	if (document.enrollForm.child3_Name.value != "" && document.enrollForm.child3_DOB.value == "") {
		alert("Please enter your child's date of birth");
		document.enrollForm.child3_DOB.focus();
		return false;
	}
	if (document.enrollForm.spouse_Name.value && document.enrollForm.spouse_DOB.value) {spouse = 1;}
	
	if (document.enrollForm.child1_Name.value && document.enrollForm.child1_DOB.value) {
		child = child + 1;
	}
	if (document.enrollForm.child2_Name.value && document.enrollForm.child2_DOB.value) {
		child = child + 1;
	}
	if (document.enrollForm.child3_Name.value && document.enrollForm.child3_DOB.value) {
		child = child + 1;
	}
	if (child == 1) {
		chPrem = 23;
	}
	if (child == 2) {
		chPrem = 46;
	}
	if (child > 2) {
		chPrem = 48;
	}
	var weeks = addDays();
	
	if (weeks==1000) {
		return false;
	}
	if (weeks < 3) {
		alert("A minimum of 3 weeks coverage is required; please change one of your dates");
		return false;
	}
	
	totalRate = prem + chPrem + (sRate*spouse);
	totalPrem = (weeks)*(totalRate);
 
	return totalPrem;
}
 
function writePremium() {
	var totPrem = getTotal();
	if (totPrem == false) {return false;}
	else {document.enrollForm.cc_Amount.value = "$" + totPrem;}
}
 
function validateForm() {
 
	/*** check for blank fields ***/
 	if (document.enrollForm.visa_Type.value == "") {
		alert("Please enter your visa type");
		document.enrollForm.visa_Type.focus();
		return false;
	}
	if (document.enrollForm.student_firstName.value == "") {
		alert("Please enter your first name");
		document.enrollForm.student_firstName.focus();
		return false;
	}
	if (document.enrollForm.student_lastName.value == "") {
		alert("Please enter your last name");
		document.enrollForm.student_lastName.focus();
		return false;
	}
	if (document.enrollForm.student_Address.value == "") {
		alert("Please enter your street address");
		document.enrollForm.student_Address.focus();
		return false;
	}
	if (document.enrollForm.student_City.value == "") {
		alert("Please enter your city");
		document.enrollForm.student_City.focus();
		return false;
	}
	if (document.enrollForm.student_State.value == "") {
		alert("Please enter your state");
		document.enrollForm.student_State.focus();
		return false;
	}
	if (document.enrollForm.student_Zip.value == "") {
		alert("Please enter your zip code");
		document.enrollForm.student_Zip.focus();
		return false;
	}
	if (document.enrollForm.student_Phone.value == "") {
		alert("Please enter your phone number");
		document.enrollForm.student_Phone.focus();
		return false;
	}
	if (document.enrollForm.student_Phone.value.length < 12) {
		alert("Please enter a valid phone number");
		document.enrollForm.student_Phone.focus();
		return false;
	}
	if ((document.enrollForm.student_Phone.value.indexOf("-") == -1) || (document.enrollForm.student_Phone.value.indexOf("(") != -1) || (document.enrollForm.student_Phone.value.indexOf(")") != -1)) {
		alert("Please enter phone number in 123-123-1234 format");
		document.enrollForm.student_Phone.focus();
		return false;
	}
	if (document.enrollForm.student_Email.value == "") {
		alert("Please enter your e-mail address");
		document.enrollForm.student_Email.focus();
		return false;
	}
  	if ((document.enrollForm.student_Email.value.indexOf("://") != -1) || (document.enrollForm.student_Email.value.indexOf("@") == -1) || (document.enrollForm.student_Email.value.indexOf(".") == -1 )|| (document.enrollForm.student_Email.value.indexOf(" ") != -1 )|| (document.enrollForm.student_Email.value.length < 6)) {
  		alert("E-mail is invalid. Please enter valid e-mail address.");
  		document.enrollForm.student_Email.focus();
  		return false;
	}
	if (document.enrollForm.student_ID.value == "") {
		alert("Please enter your student ID");
		document.enrollForm.student_ID.focus();
		return false;
	}
	if (document.enrollForm.student_DOB.value == "") {
		alert("Please enter your date of birth");
		document.enrollForm.student_DOB.focus();
		return false;
	}
	if (document.enrollForm.student_DOB.value.length < 10) {
		alert("Please enter a valid date of birth");
		document.enrollForm.student_DOB.focus();
		return false;
	}
	if (document.enrollForm.student_Gender.value == "") {
		alert("Please select your gender");
		document.enrollForm.student_Gender.focus();
		return false;
	}
	if (document.enrollForm.spouse_DOB.value != "" && document.enrollForm.spouse_Name.value == "") {
		alert("Please enter your spouse's name");
		document.enrollForm.spouse_Name.focus();
		return false;
	}
	if (document.enrollForm.child1_DOB.value != "" && document.enrollForm.child1_Name.value == "") {
		alert("Please enter your child's name");
		document.enrollForm.child1_Name.focus();
		return false;
	}
	if (document.enrollForm.child2_DOB.value != "" && document.enrollForm.child2_Name.value == "") {
		alert("Please enter your child's name");
		document.enrollForm.child2_Name.focus();
		return false;
	}
	if (document.enrollForm.child3_DOB.value != "" && document.enrollForm.child3_Name.value == "") {
		alert("Please enter your child's name");
		document.enrollForm.child3_Name.focus();
		return false;
	}
	if (document.enrollForm.spouse_Name.value != "" && document.enrollForm.spouse_DOB.value == "") {
		alert("Please enter your spouse's date of birth");
		document.enrollForm.spouse_DOB.focus();
		return false;
	}
	if (document.enrollForm.child1_Name.value != "" && document.enrollForm.child1_DOB.value == "") {
		alert("Please enter your child's date of birth");
		document.enrollForm.child1_DOB.focus();
		return false;
	}
	if (document.enrollForm.child2_Name.value != "" && document.enrollForm.child2_DOB.value == "") {
		alert("Please enter your child's date of birth");
		document.enrollForm.child2_DOB.focus();
		return false;
	}
	if (document.enrollForm.child3_Name.value != "" && document.enrollForm.child3_DOB.value == "") {
		alert("Please enter your child's date of birth");
		document.enrollForm.child3_DOB.focus();
		return false;
	}
	if (document.enrollForm.cc_firstName.value == "") {
		alert("Please enter the first name on the credit card");
		document.enrollForm.cc_firstName.focus();
		return false;
	}
	if (document.enrollForm.cc_lastName.value == "") {
		alert("Please enter the last name on the credit card");
		document.enrollForm.cc_lastName.focus();
		return false;
	}
	if (document.enrollForm.cc_Address.value == "") {
		alert("Please enter the credit card holder's street address");
		document.enrollForm.cc_Address.focus();
		return false;
	}
	if (document.enrollForm.cc_City.value == "") {
		alert("Please enter the credit card holder's city");
		document.enrollForm. cc_City.focus();
		return false;
	}
	if (document.enrollForm.cc_State.value == "") {
		alert("Please enter the credit card holder's state");
		document.enrollForm.cc_State.focus();
		return false;
	}
	if (document.enrollForm.cc_Zip.value == "") {
		alert("Please enter the credit card holder's zip code");
		document.enrollForm.cc_Zip.focus();
		return false;
	}
	if (document.enrollForm.cc_Number.value == "") {
		alert("Please enter the credit card number");
		document.enrollForm.cc_Number.focus();
		return false;
	}
	if (document.enrollForm.cc_Number.value.length < 11) {
		alert("Please enter a valid credit card number");
		document.enrollForm.cc_Number.focus();
		return false;
	}
	if (document.enrollForm.cc_cardCode.value == "") {
		alert("Please enter the card security code");
		document.enrollForm.cc_cardCode.focus();
		return false;
	}
	if (document.enrollForm.cc_expMo.value == "") {
		alert("Please enter credit card expiration month");
		document.enrollForm.cc_expMo.focus();
		return false;
	}
	if (document.enrollForm.cc_expYr.value == "") {
		alert("Please enter credit card expiration year");
		document.enrollForm.cc_expYr.focus();
		return false;
	}
	if (document.enrollForm.cc_Amount.value == "") {
		alert("Please click the Compute Premium button");
		document.enrollForm.cc_Amount.focus();
		return false;
	}
	
	var totprem = getTotal();
	
	if (("$" + totprem) != document.enrollForm.cc_Amount.value) {
		alert("Premium is incorrect. Correct premium is $" + totprem);
		document.enrollForm.cc_Amount.value = "$" + totprem;
		return false;
	}
}
 
<!-- New, broken JavaScript -->
 
function addDays() {
	var efday = document.enrollForm.effectiveDay.selectedIndex;
	var efmon = document.enrollForm.effectiveMonth.selectedIndex;
	var efyr = document.enrollForm.effectiveYear.selectedIndex;
	var termon = document.enrollForm.terminationMonth.selectedIndex;
	var terday = document.enrollForm.terminationDay.selectedIndex;
	var teryr = document.enrollForm.terminationYear.selectedIndex;
	var curmon = efmon;
	var curyr = efyr;
	var totalDays = 0;
	var numWeeks = 0;
	
	var daysInMonth = new Array(12);
	daysInMonth[1] = 31;
	daysInMonth[2] = 28;
	daysInMonth[3] = 31;
	daysInMonth[4] = 30;
	daysInMonth[5] = 31;
	daysInMonth[6] = 30;
	daysInMonth[7] = 31;
	daysInMonth[8] = 31;
	daysInMonth[9] = 30;
	daysInMonth[10] = 31;
	daysInMonth[11] = 30;
	daysInMonth[12] = 31;
 
	if (efday > daysInMonth[efmon]) {
		alert("The effective date you chose does not exist");
		return 1000;
	}
 
	if (terday > daysInMonth[termon]) {
		alert("The termination date you chose does not exist");
		return 1000;
	}
 
	// convert termination and effective dates to a generic month number
	var ter_mm = teryr * 12 + termon - 1;
	var ef_mm = efyr * 12 + efmon - 1;
	var nummonths = ter_mm - ef_mm;  // this will give # of months
	
	// take away one month if termination day of month < effective day of month
	// 1/15/2009 thru 2/15/2009 remains 1 month
	// 1/15/2009 thru 2/14/2009 (14 < 15) becomes 0 months
	if (terday < efday) nummonths -= 1;
	
	// 11/30/2008 thru 2/28/2099 is 3 months.
	// gotta give the month back.
	if (terday < efday 
		&& daysInMonth[termon] < daysInMonth[efmon]
		&& efday > daysInMonth[termon] 
		&& terday == daysInMonth[termon])
		nummonths++;
	
	return nummonths;
	
}
 
function getTotal() {
 
	var prem = 0;
	var spouse = 0;
	var sRate = 60;
	var child = 0;
	var chPrem = 0;
	var totalRate = 0;
	var totalPrem = 0;
	var insage = document.enrollForm.student_Age.selectedIndex;
	
	var effday = document.enrollForm.effectiveDay.selectedIndex;
	var effmon = document.enrollForm.effectiveMonth.selectedIndex;
	var effyr = document.enrollForm.effectiveYear.selectedIndex;
	var termmon = document.enrollForm.terminationMonth.selectedIndex;
	var termday = document.enrollForm.terminationDay.selectedIndex;
	var termyr = document.enrollForm.terminationYear.selectedIndex;
	
	if (insage == 0) {
		alert("Please select age");
		document.enrollForm.student_Age.focus();	
	}
	if (insage == 1) {
		prem = 15;
	}
	if (insage == 2) {
		prem = 18;
	}
	if (insage == 3) {
		prem = 34;
	}
	if ((effday==0) || (effmon==0) || (effyr==0)) {
		alert("Please select desired effective date");
		document.enrollForm.effectiveMonth.focus();
		return false;	
	}
	if ((termday==0) || (termmon==0) || (termyr==0)) {
		alert("Please select desired termination date");
		document.enrollForm.terminationMonth.focus();
		return false;	
	}
	if (effyr>termyr) {
		alert("Termination date must be after Effective date");
		return false;
	}
	if (effyr==termyr) {
		if (effmon>termmon) {
			alert("Termination date must be after Effective date");
			return false;
		}
		if ((effmon==termmon) && (effday>termday)) {
			alert("Termination date must be after Effective date");
			return false;
		}
	}
 
	if (document.enrollForm.spouse_DOB.value != "" && document.enrollForm.spouse_Name.value == "") {
		alert("Please enter your spouse's name");
		document.enrollForm.spouse_Name.focus();
		return false;
	}
	if (document.enrollForm.child1_DOB.value != "" && document.enrollForm.child1_Name.value == "") {
		alert("Please enter your child's name");
		document.enrollForm.child1_Name.focus();
		return false;
	}
	if (document.enrollForm.child2_DOB.value != "" && document.enrollForm.child2_Name.value == "") {
		alert("Please enter your child's name");
		document.enrollForm.child2_Name.focus();
		return false;
	}
	if (document.enrollForm.child3_DOB.value != "" && document.enrollForm.child3_Name.value == "") {
		alert("Please enter your child's name");
		document.enrollForm.child3_Name.focus();
		return false;
	}
	if (document.enrollForm.spouse_Name.value != "" && document.enrollForm.spouse_DOB.value == "") {
		alert("Please enter your spouse's date of birth");
		document.enrollForm.spouse_DOB.focus();
		return false;
	}
	if (document.enrollForm.child1_Name.value != "" && document.enrollForm.child1_DOB.value == "") {
		alert("Please enter your child's date of birth");
		document.enrollForm.child1_DOB.focus();
		return false;
	}
	if (document.enrollForm.child2_Name.value != "" && document.enrollForm.child2_DOB.value == "") {
		alert("Please enter your child's date of birth");
		document.enrollForm.child2_DOB.focus();
		return false;
	}
	if (document.enrollForm.child3_Name.value != "" && document.enrollForm.child3_DOB.value == "") {
		alert("Please enter your child's date of birth");
		document.enrollForm.child3_DOB.focus();
		return false;
	}
	if (document.enrollForm.spouse_Name.value && document.enrollForm.spouse_DOB.value) {spouse = 1;}
	
	if (document.enrollForm.child1_Name.value && document.enrollForm.child1_DOB.value) {
		child = child + 1;
	}
	if (document.enrollForm.child2_Name.value && document.enrollForm.child2_DOB.value) {
		child = child + 1;
	}
	if (document.enrollForm.child3_Name.value && document.enrollForm.child3_DOB.value) {
		child = child + 1;
	}
	if (child == 1) {
		chPrem = 23;
	}
	if (child == 2) {
		chPrem = 46;
	}
	if (child > 2) {
		chPrem = 48;
	}
	var months = addDays();
	
	if (months == 1000) {
		return false;
	}
	if (months < 3) {
		alert("A minimum of 3 months coverage is required; please change one of your dates");
		return false;
	}
	
	totalRate = prem + chPrem + (sRate*spouse);
	totalPrem = (weeks)*(totalRate);
 
	return totalPrem;
}
 
function writePremium() {
	var totPrem = getTotal();
	if (totPrem == false) {return false;}
	else {document.enrollForm.cc_Amount.value = "$" + totPrem;}
}
 
function validateForm() {
 
	/*** check for blank fields ***/
 	if (document.enrollForm.visa_Type.value == "") {
		alert("Please enter your visa type");
		document.enrollForm.visa_Type.focus();
		return false;
	}
	if (document.enrollForm.student_firstName.value == "") {
		alert("Please enter your first name");
		document.enrollForm.student_firstName.focus();
		return false;
	}
	if (document.enrollForm.student_lastName.value == "") {
		alert("Please enter your last name");
		document.enrollForm.student_lastName.focus();
		return false;
	}
	if (document.enrollForm.student_Address.value == "") {
		alert("Please enter your street address");
		document.enrollForm.student_Address.focus();
		return false;
	}
	if (document.enrollForm.student_City.value == "") {
		alert("Please enter your city");
		document.enrollForm.student_City.focus();
		return false;
	}
	if (document.enrollForm.student_State.value == "") {
		alert("Please enter your state");
		document.enrollForm.student_State.focus();
		return false;
	}
	if (document.enrollForm.student_Zip.value == "") {
		alert("Please enter your zip code");
		document.enrollForm.student_Zip.focus();
		return false;
	}
	if (document.enrollForm.student_Phone.value == "") {
		alert("Please enter your phone number");
		document.enrollForm.student_Phone.focus();
		return false;
	}
	if (document.enrollForm.student_Phone.value.length < 12) {
		alert("Please enter a valid phone number");
		document.enrollForm.student_Phone.focus();
		return false;
	}
	if ((document.enrollForm.student_Phone.value.indexOf("-") == -1) || (document.enrollForm.student_Phone.value.indexOf("(") != -1) || (document.enrollForm.student_Phone.value.indexOf(")") != -1)) {
		alert("Please enter phone number in 123-123-1234 format");
		document.enrollForm.student_Phone.focus();
		return false;
	}
	if (document.enrollForm.student_Email.value == "") {
		alert("Please enter your e-mail address");
		document.enrollForm.student_Email.focus();
		return false;
	}
  	if ((document.enrollForm.student_Email.value.indexOf("://") != -1) || (document.enrollForm.student_Email.value.indexOf("@") == -1) || (document.enrollForm.student_Email.value.indexOf(".") == -1 )|| (document.enrollForm.student_Email.value.indexOf(" ") != -1 )|| (document.enrollForm.student_Email.value.length < 6)) {
  		alert("E-mail is invalid. Please enter valid e-mail address.");
  		document.enrollForm.student_Email.focus();
  		return false;
	}
	if (document.enrollForm.student_ID.value == "") {
		alert("Please enter your student ID");
		document.enrollForm.student_ID.focus();
		return false;
	}
	if (document.enrollForm.student_DOB.value == "") {
		alert("Please enter your date of birth");
		document.enrollForm.student_DOB.focus();
		return false;
	}
	if (document.enrollForm.student_DOB.value.length < 10) {
		alert("Please enter a valid date of birth");
		document.enrollForm.student_DOB.focus();
		return false;
	}
	if (document.enrollForm.student_Gender.value == "") {
		alert("Please select your gender");
		document.enrollForm.student_Gender.focus();
		return false;
	}
	if (document.enrollForm.spouse_DOB.value != "" && document.enrollForm.spouse_Name.value == "") {
		alert("Please enter your spouse's name");
		document.enrollForm.spouse_Name.focus();
		return false;
	}
	if (document.enrollForm.child1_DOB.value != "" && document.enrollForm.child1_Name.value == "") {
		alert("Please enter your child's name");
		document.enrollForm.child1_Name.focus();
		return false;
	}
	if (document.enrollForm.child2_DOB.value != "" && document.enrollForm.child2_Name.value == "") {
		alert("Please enter your child's name");
		document.enrollForm.child2_Name.focus();
		return false;
	}
	if (document.enrollForm.child3_DOB.value != "" && document.enrollForm.child3_Name.value == "") {
		alert("Please enter your child's name");
		document.enrollForm.child3_Name.focus();
		return false;
	}
	if (document.enrollForm.spouse_Name.value != "" && document.enrollForm.spouse_DOB.value == "") {
		alert("Please enter your spouse's date of birth");
		document.enrollForm.spouse_DOB.focus();
		return false;
	}
	if (document.enrollForm.child1_Name.value != "" && document.enrollForm.child1_DOB.value == "") {
		alert("Please enter your child's date of birth");
		document.enrollForm.child1_DOB.focus();
		return false;
	}
	if (document.enrollForm.child2_Name.value != "" && document.enrollForm.child2_DOB.value == "") {
		alert("Please enter your child's date of birth");
		document.enrollForm.child2_DOB.focus();
		return false;
	}
	if (document.enrollForm.child3_Name.value != "" && document.enrollForm.child3_DOB.value == "") {
		alert("Please enter your child's date of birth");
		document.enrollForm.child3_DOB.focus();
		return false;
	}
	if (document.enrollForm.cc_firstName.value == "") {
		alert("Please enter the first name on the credit card");
		document.enrollForm.cc_firstName.focus();
		return false;
	}
	if (document.enrollForm.cc_lastName.value == "") {
		alert("Please enter the last name on the credit card");
		document.enrollForm.cc_lastName.focus();
		return false;
	}
	if (document.enrollForm.cc_Address.value == "") {
		alert("Please enter the credit card holder's street address");
		document.enrollForm.cc_Address.focus();
		return false;
	}
	if (document.enrollForm.cc_City.value == "") {
		alert("Please enter the credit card holder's city");
		document.enrollForm. cc_City.focus();
		return false;
	}
	if (document.enrollForm.cc_State.value == "") {
		alert("Please enter the credit card holder's state");
		document.enrollForm.cc_State.focus();
		return false;
	}
	if (document.enrollForm.cc_Zip.value == "") {
		alert("Please enter the credit card holder's zip code");
		document.enrollForm.cc_Zip.focus();
		return false;
	}
	if (document.enrollForm.cc_Number.value == "") {
		alert("Please enter the credit card number");
		document.enrollForm.cc_Number.focus();
		return false;
	}
	if (document.enrollForm.cc_Number.value.length < 11) {
		alert("Please enter a valid credit card number");
		document.enrollForm.cc_Number.focus();
		return false;
	}
	if (document.enrollForm.cc_cardCode.value == "") {
		alert("Please enter the card security code");
		document.enrollForm.cc_cardCode.focus();
		return false;
	}
	if (document.enrollForm.cc_expMo.value == "") {
		alert("Please enter credit card expiration month");
		document.enrollForm.cc_expMo.focus();
		return false;
	}
	if (document.enrollForm.cc_expYr.value == "") {
		alert("Please enter credit card expiration year");
		document.enrollForm.cc_expYr.focus();
		return false;
	}
	if (document.enrollForm.cc_Amount.value == "") {
		alert("Please click the Compute Premium button");
		document.enrollForm.cc_Amount.focus();
		return false;
	}
	
	var totprem = getTotal();
	
	if (("$" + totprem) != document.enrollForm.cc_Amount.value) {
		alert("Premium is incorrect. Correct premium is $" + totprem);
		document.enrollForm.cc_Amount.value = "$" + totprem;
		return false;
	}
}

Open in new window

Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

macrolific,

You should post in the other Q to let that expert know you opened this up for the follow up issue.  You can just post the URL of this Q in a comment there.

When is writePremium called?  Put an alert in it to see what the value is for totPrem.  Make sure it is on the second line of that function.  What is the result?

Let me know if you have any questions or need more information.

b0lsc0tt
ASKER CERTIFIED SOLUTION
Avatar of Jonathan Greenberg
Jonathan Greenberg
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I answered your original question.
I'll mock up a page (with all the fields, etc) with which to test the code with, and let you know the results.
oops, I missed one reference to weeks.  
Your welcome!  Since it seems my comment didn't help or relate to the fix it might be more appropriate to have your comment accepted as the answer.  If you agree let me know and I can get that done.  I am glad it is fixed and appreciate the thought but don't need to get the points and answer if I didn't provide them. :)
bol
Avatar of Jonathan Greenberg

ASKER

It's OK, Kevin, I think I'm in good shape now. I need to try to make another major change to the script now, but I'll post that in a new question.

b0lsc0tt, thanks for pointing that out.

I actually tried to do as you're suggesting once before. I pay monthly to get help here, so I don't care about getting points for myself. But for the sake of accuracy, I once tried to accept my answer to my own question. I had problems with it. I don't remember the specifics, but I was contacted by a moderator and asked to make some sort of clarification regarding my intentions or reasoning. I ended up feeling like it was more trouble than it was worth. Since then whenever the situation has presented itself, I've just given the points to whomever tried to help me, whether successfully or not.

I'm fine if you want to keep the points. But if you wish for the page to reflect that mine was the correct answer, great, no worries. And thanks for the offer.