I am creating an web application where I am now checking whether a emailId is already registered with us or not".If the emailid exists the appropriate message is reflected in div_Error.innerHtml
But there is something unusual happening here. If I dont put alert() statement in the first line of fun_getOutput() function then xmlhttp.readyState == 4 doesn't fire. And same If I put it then it works like a charm.
Is it some time delaying problem in Javascript/Ajax.
Please discuss.
- Code: Select all
function fun_GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
function fun_AjaxCheckExistingEmailId(EmailId)
{
xmlhttp=fun_GetXmlHttpObject();
if (xmlhttp==null)
{
return;
}
url="ajax_CheckExistingEmailId.jsp?";
url+="textfield_EmailId="+EmailId;
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
xmlhttp.onreadystatechange=fun_getOutput();
}
function fun_getOutput()
{
alert("**** [b]I DONT KNOW WHY THIS IS REQUIRED[/b] ****");
[color=#FF4000] //But if I comment the above alert statement it doesn't go inside below [B]IF[/B] block, Othewrwise it works like a charm. [/color]
if (xmlhttp.readyState==4)
{
var div_Error =document.getElementById("div_Error_Id");
if(xmlhttp.responseText.indexOf("EmailId_Exists")!=-1)
{
div_Error.innerHtml="Email Id Exists"
}
else{
div_Error.innerHtml="Ok"
}
}
}
Thanks,
Venkat


