Javascript Validation Help

Need another set of eyes to determine why this is failing. The error is simply “Error on page” which is as clear as mud.

I am attempting to expand my validation code for my web form. What I would like to do is check to see if a radio button field is checked, if so, check a few other fields. If it is not checked, return an error message to the user.

Here’s a portion of my code:

function validate() {

errMSG = “”

var f = document.forms[0]

var chkd = false

for (counter = 0; counter < f.JobNoTechDoc.length; counter++){

if (f.JobNoTechDoc[counter].checked){

chkd = true;

}else{

chkd = false;

}

}

If chkd == false{

if (errMSG != “”) {

     errMSG+="\nEnter the error message here";

	}else {

		errMSG+="Please correct the following:\n\nEnter the error message here\n";

	}

}

If chkd == true{

//start checking the other fields now

if(f.RSFamily1.selectedIndex < 1){

	if (errMSG!="") {

		errMSG += "Enter the Siplast Membrane System\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Siplast Membrane System\n";

			}

	}

}

}

Subject: Javascript Validation Help

I think case senstivity is the issue. I can’t help noticing that in some of your if statements you are using “If” and not “if”. This had me going for at least 4 hours the first time i made this error. You MUST use lowercase for if, else, for and so on.

Also, try disabling the “Show browser friendly error messages” in Internet Explorer options - this can sometimes help!

Or use firefox to test

Subject: Javascript Validation Help

What is f.JobNoTechDoc.length ? is this a Field? what kind of field is it? can you really access it like that?

Have you already tried “try{} catch{}” blocks in your JavaScript?

Subject: RE: Javascript Validation Help

This field is a checkbox field – choices are 1-6 – no default is set.

Yes, I can access it.

Subject: Javascript Validation Help

Lisa,

Since this is only a portion of the code it makes it difficult for others to debug. Either post all the JavaScript code or add lines at the top that show how you’ve defined global variables.

For example, I don’t see “var errMSG” so I don’t know if you’ve forgotten to declare errMSG. Also, you are not ending statements with semicolons which are required in JavaScript. These could be your errors or maybe it is something else.

Regarding that other poster’s advice to use try/catch blocks, as far as I know, there is no such thing in JavaScript. This applies only to Java.

Ken

Subject: RE: Javascript Validation Help

Here is my entire validation code. Please note that, if I remove the proposed new code, no errors occur.

//****************************

function validate() {

errMSG = “”

var f = document.forms[0];

if(f.JobDateEstStart.value == ‘’) {

if (errMSG != “”) {

     errMSG+="\nEnter the Estimated Start Date";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Estimated Start Date\n";

	}

}

if(f.RSSqrs.value == ‘’) {

if (errMSG!=“”) {

	     errMSG+="Enter the Total Squares\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Total Squares\n";

	}

}

if(f.JobGuaranteeType.selectedIndex<1){

if (errMSG!=“”) {

		errMSG += "Select a Guarantee Type\n";

	}else {

		errMSG+="Please correct the following:\n\nSelect a Guarantee Type\n";

	}

}	

if(f.JobGuaranteeDuration.selectedIndex<1){

if (errMSG!=“”) {

		errMSG += "Select a Guarantee Duration\n";

	}else {

		errMSG+="Please correct the following:\n\nSelect a Guarantee Duration\n";

	}

}	

if(f.JobName.value == ‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Project Name\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Project Name\n";

	}

}	

if(f.JobSiteAddress.value ==‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Job Site Address\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Job Site Address\n";

	}

}	

if(f.JobSiteCity.value ==‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Job Site City\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Job Site City\n";

	}

}	

if(f.JobSiteState.value == ‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Job Site State\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Job Site State\n";

	}

}	

if(f.JobSiteZip.value ==‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Job Site Zip\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Job Site Zip\n";

	}

}	

if(f.JobSiteBldgUse.selectedIndex < 1){

if (errMSG!=“”) {

		errMSG += "Select the Building Use\n";

	}else {

		errMSG+="Please correct the following:\n\nSelect the Building Use\n";

	}

}	

if(f.JobBldgOwnerName.value == ‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Building Owner Name\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Building Owner Name\n";

	}

}	

if(f.JobOwnerAddress.value == ‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Building Owner Address\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Building Owner Address\n";

	}

}	

if(f.JobOwnerCity.value == ‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Building Owner City\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Building Owner City\n";

	}

}	

if(f.JobOwnerState.value == ‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Building Owner State\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Building Owner State\n";

	}

}	

if(f.JobOwnerZip.value == ‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Building Owner Zip\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Building Owner Zip\n";

	}

}	

if(f.JobRoofContractor.value == ‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Roofing Contractor Name\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Roofing Contractor Name\n";

	}

}	

if(f.JobRFAddress.value == ‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Roofing Contractor Address\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Roofing Contractor Address\n";

	}

}	

if(f.JobRFCity.value == ‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Roofing Contractor City\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Roofing Contractor City\n";

	}

}	

if(f.JobRFState.value == ‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Roofing Contractor State\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Roofing Contractor State\n";

	}

}	

if(f.JobRFZip.value == ‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Roofing Contractor Zip\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Roofing Contractor Zip\n";

	}

}

if(f.JobRFContactName.value == ‘’) {

if (errMSG!=“”) {

		errMSG += "Enter the Roofing Contractor Contact\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Roofing Contractor Contact\n";

	}

}

//BEGINNING OF NEW CODE

var chkd = false;

for (counter = 0; counter < f.JobNoTechDoc.length; counter++){

if (f.JobNoTechDoc[counter].checked){

chkd = true;

}

}

if(chkd != false){

if(f.RSFamily1.selectedIndex < 1){

	if (errMSG!="") {

		errMSG += "Enter the Siplast Membrane System\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Siplast Membrane System\n";

			}

	}

if(f.RSProjectType1.selectedIndex < 1){

	if (errMSG!="") {

		errMSG += "Enter the Project Type\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Project Type\n";

	}

}

if(f.RSBasePly1.selectedIndex < 1){

	if (errMSG!="") {

		errMSG += "Enter the Base Ply for the Siplast Roof System\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Base Ply for the Siplast Roof System\n";

	}

}

if(f.RSFinishPly1.selectedIndex < 1){

	if (errMSG!="") {

		errMSG += "Enter the Finish Ply for the Siplast Roof System\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Finish Ply for the Siplast Roof System\n";

	}

}

if(f.RSRoofDkType1.selectedIndex < 1){

	if (errMSG!="") {

		errMSG += "Enter the Roof Deck Type\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Roof Deck Type\n";

	}

}

if(f.RSRoofDkSlope1.selectedIndex < 1){

	if (errMSG!="") {

		errMSG += "Enter the Slope per Foot\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the Slope per Foot\n";

	}

}	

}else{

if (errMSG!="") {

		errMSG += "Enter the # of Roof Constructions\n";

	}else {

		errMSG+="Please correct the following:\n\nEnter the # of Roof Constructions\n";

	}

}

//END OF NEW CODE

if (errMSG != “”) {

alert(errMSG);

f.SaveOptions.value = ‘0’;

return false

}

f.SaveOptions.value = ‘1’;

return true

}

//****************************