Can someone tell me what the bug is in this JavaScript code?

Lotus Version 8.0.2

Everything works fine in this code until I add the line of code for the “BillFold” field.

After I enter that section of code, than it seems like it goes in a loop.

The “BillFold” field is a dialog list field and it’s position is the last field

on the form.

In this field, I have the call for the validation in the “OnBlur” event.

The code for the JavaScript call is "validate(this)

Any ideas why this is happening? What do I have coded incorrectly?

Thanks much for any comments or assistance.

Jean

The code listed below is in the JSHeader section.

//The Input Validation Function for all required fields on a form.

function validate(){

var validatemsg;				

var validateflag;				

validateflag = "false";				

var serviceOK = 0;

This is the code that seems to give me a problem.

  if(document.forms[0].BillFold[0].selected){

	validatemsg="FIELD ERROR: Please select a value for the Billing Folder.";

	validateflag="true";

		document.forms[0].BillFold.focus()

}

End of the code giving the problem

   if(document.forms[0].ActCodes.value == ""){

   	validatemsg="FIELD ERROR: Please enter the Repair Action Codes.";

      validateflag="true";

      document.forms[0].ActCodes.focus()

   }	



    if(document.forms[0].HrMeter.value == ""){		

	validatemsg="FIELD ERROR: Please enter an Hour Meter value.";	

	validateflag="true";	

	document.forms[0].HrMeter.focus()

}

	

if(document.forms[0].HrMeter.value != ""){			

	var theHrM = document.forms[0].HrMeter.value		

	var charsHrMtrlong = theHrM.length		

	var anError1 = 0		

	

	switch(charsHrMtrlong){		

		case 1:	

			if(isNaN(theHrM)){

				anError1 = 1;

			}

			break

		case 2:	

			if(isNaN(theHrM)){

				anError1 = 1;

			}

			break

		

		case 3:	

			if(isNaN(theHrM)){

				anError1 = 1;

			}

			break

		case 4:	

			if(isNaN(theHrM)){

				anError1 = 1;

			}

			break

		case 5:	

			if(isNaN(theHrM)){

				anError1 = 1;

			}

			break

		default:	

			anError1 = 1;

	}		



	if(anError1){		

		validatemsg="FIELD ERROR: The Hour Meter is required to be numeric, 5 digits..";	

		validateflag="true";	

		document.forms[0].HrMeter.focus()	

	}		

}			



    

    if(document.forms[0].TruckSN.value == ""){			

	validatemsg="FIELD ERROR: Please enter the Truck SN.";		

	validateflag="true";		

	document.forms[0].TruckSN.focus()		

}			

 	if(document.forms[0].fClock.value == ""){			

	validatemsg="FIELD ERROR: Please enter 1st Time/Type detail";		

	validateflag="true";		

	document.forms[0].fClock.focus()		

}			

if(document.forms[0].fClock.value != ""){			

 	var thefClock = document.forms[0].fClock.value		

 	var allchars = thefClock.length		

	

	if(allchars> 25){		

		validatemsg="FIELD ERROR: The 1st Time/Type is required to be less than 25 characters in length..";	

		validateflag="true";	

		document.forms[0].fClock.focus()	

	}		

}			 

if(document.forms[0].POPM.value == ""){			

	validatemsg="FIELD ERROR: Please enter WO # detail";		

	validateflag="true";		

	document.forms[0].POPM.focus()		

}			

if(document.forms[0].POPM.value != ""){			

 	var thePOPM = document.forms[0].POPM.value		

 	var totalchars = thePOPM.length		

 	//validateflag="true";		

	//if there's a problem, repond.		

	if(totalchars> 25){		

		validatemsg="FIELD ERROR: The WO# is required to be less than 25 characters in length..";	

		validateflag="true";	

		document.forms[0].POPM.focus()	

	}		

}	



if(document.forms[0].VanNum.value == ""){		

	validatemsg="FIELD ERROR: Please enter a Van Number in the Van Number field.";		

	validateflag="true";		

	document.forms[0].VanNum.focus()	

}			

if(document.forms[0].VanNum.value != ""){			

 	var theSSN = document.forms[0].VanNum.value		

 	var charslong = theSSN.length		

 	var anError = 0		

 	//validateflag="true";		

	switch(charslong){		

		case 1:	

			if(isNaN(theSSN)){

			anError = 1;

			}

			break

		case 2:	

			if(isNaN(theSSN)){

			anError = 1;

			}

			break

			

		case 3:	

			if(isNaN(theSSN)){

			anError = 1;

			}

			break

		default:	

			anError = 1;

	}		

	//if there's a problem, repond.		

	if(anError){		

		validatemsg="FIELD ERROR: Van Number is required to be numeric, length 2 or 3 digits..";	

		validateflag="true";	

		document.forms[0].VanNum.focus()	

	}		

}			

	

if(validateflag == "true"){			

	alert(validatemsg);		

}			

else{			

	var x = new Boolean(true);		

	ok=x.valueOf();		

			

	a=confirm('Do you wish to submit at this time?  If so, press the Save button.');		

			

	if (a==ok){		

		document.forms[0].submit.focus(); //to delete the records	

		}	

	else{		

	document.forms[0].VanNum.focus()		

		}	

 }				

}

Subject: JS

For a Web app ?

I would write:

if(this.form.elements[‘BillFold’].options[this.form.elements[‘BillFold’].selectedIndex].value==“”)

But I am no JS guru…

Thierry Cayla

http://dominoeffects.serveblog.net