Jump to content

New Tracking Code Breaks My Js


mboehler3

Recommended Posts

I want to add Google Tracking code to my JavaScript, and when I add the code it breaks. Here's what the original JS looks like:

							function checkrefervalues(){								message="";								if (document.referaclient.companyname.value.length ==0){										message = message+"Please enter your Company Name.\n";									}								if(document.referaclient.name.value.length ==0){												message = message+"Please enter your Name.\n";								}																	if (document.referaclient.email.value.length ==0){										message = message+"Please enter your Email Address.\n";									}									else {									 	checkemail(document.referaclient.email.value)									}																		if(document.referaclient.areacode.value.length != 3 || document.referaclient.exchange.value.length != 3 || document.referaclient.phonenumber.value.length != 4){										if(IsNumeric(document.referaclient.areacode.value) != 1	|| IsNumeric(document.referaclient.exchange.value) != 1 || IsNumeric(document.referaclient.phonenumber.value) != 1){										message = message+"Please enter a Numeric Phone Number.\n";										}										else { message = message+"Please enter a Phone Number.\n";}								}								else{ 									if(IsNumeric(document.referaclient.areacode.value) != 1	|| IsNumeric(document.referaclient.exchange.value) != 1 || IsNumeric(document.referaclient.phonenumber.value) != 1){									message = message+"Please enter a Numeric Phone Number.\n";									}								}																if(document.referaclient.exchange.value == 555){									message = message+"Please enter a Valid Phone Number.\n";								}																if (document.referaclient.terms.checked ==false){									message = message+"Please agree to the Terms & Conditions.\n";								}																if (message.length > 0){											alert(message);										return false;									}																					return true;								}																			function checkemail(str){								var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i								if (filter.test(str))								testresults=true								else{								message = message + "Email address seems incorrect (check @ and .'s)\n"								return false;								}								}							function IsNumeric(sText)								{								   var ValidChars = "0123456789";								   var IsNumber=true;								   var Char;																 								   for (i = 0; i < sText.length && IsNumber == true; i++) 									  { 									  Char = sText.charAt(i); 									  if (ValidChars.indexOf(Char) == -1) 										 {										 IsNumber = false;										 }									  }									 return IsNumber;	   							}													var isNN = (navigator.appName.indexOf("Netscape")!=-1);						function autoTab(input,len, e) {						  var keyCode = (isNN) ? e.which : e.keyCode; 						  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];						  if(input.value.length >= len && !containsElement(filter,keyCode)) {							input.value = input.value.slice(0, len);							input.form[(getIndex(input)+1) % input.form.length].focus();						  }						  function containsElement(arr, ele) {							var found = false, index = 0;							while(!found && index < arr.length)							if(arr[index] == ele)							found = true;							else							index++;							return found;						  }						  function getIndex(input) {							var index = -1, i = 0, found = false;							while (i < input.form.length && index == -1)							if (input.form[i] == input)index = i;							else i++;							return index;						  }						  return true;						}

And my new code simply replaces:

if (message.length > 0){	   		alert(message);		return false;		}																			return true;}

with:

if (message.length > 0){	   		alert(message);		return false;		}pageTracker._trackEvent('Accountant Forms', 'Referral’);									 return true;}

Can someone help me out as to what the problem is? Any help is very appreciated! Thanks.

Link to comment
Share on other sites

Are you getting error messages from Javascript? Have you tried running the page tracking code outside of the rest of your code?
Well, I am testing it by hitting the submit button without entering any information in the form fields. On the working form, a JavaScript window will pop up and say "hey, you need to enter this, this and this". But with the new JS, I hit submit with no information and it takes me to the thank-you page I have set up when a user submits their information. I'm not sure what you mean in your second question... do you mean taking the code where it is and moving it around the existing code? I have tried moving it to the top and bottom of the JS, and get the same error result.
Link to comment
Share on other sites

So, what's the problem? Is the problem that the one line of tracking code causes an error, or that the form submits when it shouldn't? You said "when I add the code it breaks", what breaks?
Right, the form submits when it shouldn't. When I hit submit with blank information, it takes me to the thank you page but lists this error above the form: "Error - Please check the phone number and try again."I should add that this ASP logic is included in the HTML:
<% 		'declare vars for sending email		Dim bReturn, dtSendDate		Dim sMailSubject, sMailBody, sMailFromAddress, sMailFromName, sMailToAddress, sMailToName				dim sendemail,emailbodytext,refererror		sendemail = ""		sendemail = Request.Form("sendemail")		refererror = ""				Function IllegalChars(sInput)				Dim sBadChars, iCounter				IllegalChars=False				sBadChars=array("drop", "--", "insert", "delete", "xp_", "#", "%","(", ")", "/", "\", ":", ";", "<", ">", "=", "[", "]", "?", "`", "|")				For iCounter = 0 to uBound(sBadChars)					If Instr(sInput,sBadChars(iCounter))>0 Then						IllegalChars=True					End If				Next			End function		 		 If sendemail = "rac" Then		 	dim str_name, str_phone, str_email, ephonelen, str_companyname		 			str_name = Request.Form("name")			str_phone = Request.Form("areacode") & Request.Form("exchange") & Request.Form("phonenumber")			ephonelen = Len(str_phone)			str_email = Request.Form("email")			str_companyname = Request.Form("companyname")								if (str_name = "") or (str_email = "") or (str_companyname = "") then	 			refererror = "missinginfo"			end if						if (str_phone = "") or (IsNumeric(str_phone) = false) or (ephonelen <> 10) then				refererror = "phonenumber"			end if						If IllegalChars(str_name)=True OR IllegalChars(str_phone)=True OR IllegalChars(str_email)=True Then				refererror = "dataintegrity"			End If		 		 	if refererror = "" then					 	emailbodytext = "name | phonenumber | email | companyname | " & Request.Form("name") & " |" & Request.Form("areacode") & Request.Form("exchange") & Request.Form("phonenumber") & " |" & Request.Form("email") & " |" & Request.Form("companyname")				dtSendDate = Now()			 	sMailSubject = "Resell a Client - Accountant Reseller Information Request"				  sMailBody = emailbodytext				  sMailFromAddress = "doug@sure.com"				sMailFromName = "Doug"				sMailToAddress = "cps@sure.com"				sMailToName = "Frank Zesty"				bReturn = oCustServ.SendMessage("----", 99, sMailFromAddress, sMailFromName, sMailToAddress, sMailToName, sMailBody, sMailSubject, dtSendDate)				'============= CHECK FOR ERROR ==================				if bReturn = False then bReturn = SetErrorInfo (1, "----", 0)				'=========== END CHECK FOR ERROR ================			 End If 		 End If %>

And this logic is in the HTML as well:

<%if sendemail = "rac" and refererror <> "" Then				If refererror = "phonenumber" then Response.Write ("<p class='inputboxheaders error'><strong>Error - Please check the phone number and try again.</strong>") end if				If refererror = "missinginfo" then Response.Write ("<p class='inputboxheaders error'><strong>Error - You are missing information, please answer all of the questions below so that we may better serve you.</strong>") end if				If refererror = "dataintegrity" then Response.Write ("<p class='inputboxheaders error'><strong>Error - There was a problem with some of your answers, please try again.</strong>") end if			 end If%>

Does this help any?

Link to comment
Share on other sites

Add some code to your checkrefervalues function to tell what it's doing, have it print the values it's using or the message string and where the code is going so you can tell why it's not returning false. You have an onsubmit event on the form, right?

Link to comment
Share on other sites

Add some code to your checkrefervalues function to tell what it's doing, have it print the values it's using or the message string and where the code is going so you can tell why it's not returning false. You have an onsubmit event on the form, right?
Yes, at the top of the form I have this code:
<script language="JavaScript" src="/surechoice/resell_check.js" type="text/javascript"></script><form action="#thankyou" method="post" name="referaclient" onSubmit="return checkrefervalues();"><input type="hidden" name="sendemail" value="rac">

The problem is, I'm not really familiar with JS... I've enrolled in a course on web scripting this semester but so far I've only had one class. I don't know how to do any of what you described. I was hoping this issue I'm having would be a quick fix... not so sure of that now.

Link to comment
Share on other sites

You can just add alert statements to print the values of the variables you're working with so you can check them, or to do an alert when it goes inside an if statement so that you know that it went in the if statement. The point is to figure out exactly what the code is doing when it runs, so the best way to figure that out is have the code tell you where it is. If you have Firebug set up with Firefox, you can also use console.log instead of alert to have the script continue running (alert will pause execution until you click OK).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...