function validateEmail(){
var TCode = document.getElementById('email').value;
if(TCode.length==0)
{
email_info.innerHTML="This field is required";
return false;
}
email_info.innerHTML=" ";
var atpos=TCode.indexOf("@");
var dotpos=TCode.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=TCode.length)
{
email_info.innerHTML="Not a valid e-mail address";
return false;
}
email_info.innerHTML=" ";
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("email_info").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","get_email.jsp?email="+TCode,true);
xmlhttp.send();
return true;
}
On blur of an email input field, the function above is called to validate the email. However, the issue arises when attempting to restrict form submission if the email already exists in the database. While it's possible to display a message if the email exists, preventing the form from submitting is challenging. Any suggestions on how to solve this problem?