You need to sign in to do that
Don't have an account?
issues with javascript form validation on web to lead page
i have web to lead page that includes some javascript code used to validate email addresses and verify all fields are filled out. the page routes to a record type but when the javascript validation is included it blocks the routing.
here is the HTML that includes the javascript that references the validation code:
<form name="information" action= "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" onsubmit="return validateForm();” >
when i take out 'onsubmit="return validateForm();” ' the information is routed to the correct record type but it wont validate the email or that the fields are filled out. the javascript code is accessed by this command.
here is the javascript code:
<script> function validateForm() { var x=document.forms["information"]["first_name"].value; if (x==null || x=="") { alert("First name must be filled out"); return false; } var x=document.forms["information"]["last_name"].value; if (x==null || x=="") { alert("Last name must be filled out"); return false; } var x=document.forms["information"]["email"].value; if (x==null || x=="") { alert("Email must be filled out"); return false; } var x=document.forms["information"]["email"].value; var atpos=x.indexOf("@"); var dotpos=x.lastIndexOf("."); if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) { alert("Not a valid e-mail address"); return false; } var x=document.forms["information"]["confirm_email"].value; if (x==null || x=="") { alert("Confirm email must be filled out"); return false; } var x=document.forms["information"]["email"].value; var pass= document.getElementById("email").value var confPass = document.getElementById("confirm_email").value if(pass != confPass) { alert('Email fields do not match'); return false; } var x=document.forms["information"]["company"].value; if (x==null || x=="") { alert("Company must be filled out"); return false; } var x=document.forms["information"]["state"].value; if (x==null || x=="") { alert("State/Province must be filled out"); return false; } } </script>
Change the next lines:
For this:
And should solve your problem.
PD: Better late than never :P
Thanks Pepiño i will give this a shot.