matthewl -1 Junior Poster in Training

I have been working on an email validation functions that would validate the e-mail and I am having problems communicating the "EmailState" from the ajax. The state the php gives is 1 if the email address exists and zero if it doesn't.

I do this check with Email_Exists() and when I run the functions below and it fails to return the value of the EmailStat in real time. In other words it will only see the last EmailStat that ran. What is causing it not to be seen the first time? I have the javascript in the <head> element. I would if it is my scope I am using.

<input id="EmailStat" value="0">
    <div align="center"><span class="style13">Please enter your Account and Credit Card Information Below:</span></div>
	<div id="Req_Fields" class="style18" align="center"></div>
	<div id="Email_Format" class="style18" align="center"></div>
	<div id="Email_Exists" class="style18" align="center"></div>

how I call the functions ( the ok variable returns the form false) :

//run a check to see if email exists
Email_Exists();
//handle email validation
Email_State = chk_email();
if(Email_State == false) {
ok = false;
}

These functions analyze the email text box:

function Email_Exists() {
Email = document.getElementById('Email');
//check if it exists in db
if(window.XMLHttpRequest) {
  xmlhttp = new XMLHttpRequest();
  if(xmlhttp.overrideMimeType) {
   xmlhttp.overrideMimeType('text/xml');
  }
 } else if(window.ActiveXObject) {
  try {
   xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
  } catch(e) {
   try {
    xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
   } catch(e) {
    xmlhttp = false;
   }
  }
 }
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
  {
  xml = xmlhttp.responseXML;
  r = xml.getElementsByTagName('result')[0].childNodes[0].nodeValue;
  document.getElementById('EmailStat').value = r;
  }
}
xmlhttp.open("GET","val_su.php?Email="+Email.value,true);
xmlhttp.send(null);
}

//check email validation
function chk_email() {
Email = document.getElementById('Email');
if(Email.value != "") {

//check format
var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(Email.value)) {
document.getElementById('Email_Format').InnerHTML = "Email Address (highlighted in blue) is not the proper format.";
Email.className = "email_error";
return false;
}

//set result if someone owns that email
if(document.getElementById('EmailStat').value == 1) {
Email.className = "email_error";
document.getElementById('Email_Exists').InnerHTML = "Email Address (highlighted in blue) already exists in the SpiderMaze vendor system.";
return false;
}
}
//it passed validation
return true;
}

Thanks for you time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.