Question : Validation JS Error in FireFox Only

I had this great, compact validation & submit script refined last week by leakim971 and it was working perfectly. I noticed a problem then, in FireFox. If I run this script as is, in FireFox, it executes perfectly. However, if I add just one more input field (for an email address, let's say) and add another 'if' statement to validate that field, to read like this:
            if (document.reg_form.email.value=="") {
                  themessage = themessage + " - E-Mail:\n";
            }
what happens is that FireFox throws up an error stating "Application Error - An error has occurred in the program". That's all it says. Doesn't process the form information.

I've attached the code below to show how it looks with the added 'if' statement for the email validation field. Has anyone any experience with this kind of FireFox issue and know a workaround?

Thanks.

Cayce
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans nom</title>
<SCRIPT LANGUAGE="JavaScript">
function verify() {
var themessage = "Please Check the Following Fields: \n";
		
if (document.reg_form.Name.value=="") {
themessage = themessage + " - Name:\n";
//Adding this next if statement causes a problem in FireFox
}if (document.reg_form.email.value=="") {
themessage = themessage + " - E-Mail:\n";
}
//alert if fields are empty and cancel form submit
if (themessage != "Please Check the Following Fields: \n") {
alert(themessage);
return false;
}
return true;
}
</script>
<script type="text/javascript">
<!--
	function frmSubmit() {
		document.reg_form.target = "_blank";
		document.reg_form.action = "FormOrder.pl"
		document.reg_form.submit();
		setTimeout('document.reg_form.target = "_self";window.location = "thank_you.shtml"',500);
	}
	
// -->
</script>
</head>
<body>
<form name="reg_form" id="reg_form" method="get" >

	<input name="Name" type="text" id="Name" />
	<input name="email" type="text" id="email" />

	<a href="#" onClick="if(verify()) frmSubmit(); else return false;"><img src="http://www.tarantin.com/images/orderForm_btn.gif" border="0"></a>
</form>
</body>
</html>

Answer : Validation JS Error in FireFox Only

This works.  You need to not use ' onload="javascript:purchProg_swap();"' until it actually exists in your page.  Javascript usually stops executing on the first error.  I also rearranged your code.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<script type="text/javascript">
	function verify() {
		var srrmsg = "";
		
		if (document.reg_form.Full_Name.value=="") {
			srrmsg = srrmsg + " - Full Name:\n";
		}
//Adding another IF statement throws error in FireFox
			if (document.reg_form.email.value=="") {
			srrmsg = srrmsg + " - email:\n";
		}

		//alert if fields are empty and cancel form submit
		if (srrmsg != "") {
			alert("Please Check the Following Fields: \n"+srrmsg);
			return false;
		}
		return true;
	}
</script>

<script type="text/javascript">
<!--
	function frmSubmit() {
		document.reg_form.target = "_blank";
		document.reg_form.action = "FormMail_Contact.pl"
		document.reg_form.submit();
		setTimeout('document.reg_form.target = "_self";window.location = ""',0);
	}
	
// -->
</script>

</head>
<body>

<form name="reg_form" id="reg_form" method="post" >
Full Name: <input type="text" name="Full_Name" id="frmname" class="frmfld"  value=""  /><br />

Email : <input type="text" name="email" id="frmemail" class="frmfld"  value=""  /><br />

<a href="#" onClick="if(verify()) frmSubmit(); else return false;"><img src="http://www.cayceweb.com/images/btn_contact.jpg" width="117" height="26" border="0"></a>
</form>

</body>
</html>
Random Solutions  
 
programming4us programming4us