• Pepiño
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

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>