[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

What is preventing my JS from working?

Posted on 2009-07-01
7
Medium Priority
?
218 Views
Last Modified: 2012-05-07
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

0
Comment
Question by:Jonathan Greenberg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
7 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24759704
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
0
 

Accepted Solution

by:
Jonathan Greenberg earned 0 total points
ID: 24759732
Thank you, b0lsc0tt. I found the problem just a moment ago. On line 188 of the new script, I needed to change

     totalPrem = (weeks)*(totalRate);
to
     totalPrem = (months)*(totalRate);

That's all it was. Thanks for helping.
0
 
LVL 12

Expert Comment

by:kevin_u
ID: 24759757
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 12

Expert Comment

by:kevin_u
ID: 24759761
oops, I missed one reference to weeks.  
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24759764
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
0
 

Author Comment

by:Jonathan Greenberg
ID: 24759795
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.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question