moin1407
03-05-2011, 04:47 PM
HI
Why found variable not working properly in if statement?
The found variable working properly in if ( user.length < 6 || user.length > 20 ) but not working in if(code <=0). why? i want to send found value via return at the end of the function username_check()
please anyone resolve this.
function pullAjax(){
var a;
try{
a=new XMLHttpRequest()
}
catch(b)
{
try
{
a=new ActiveXObject("Msxml2.XMLHTTP")
}catch(b)
{
try
{
a=new ActiveXObject("Microsoft.XMLHTTP")
}
catch(b)
{
alert("Your browser broke!");return false
}
}
}
return a;
}
function username_check()
{
var found = 0;
var x = document.getElementById('username');
var username_msg = document.getElementById('username_msg');
user = x.value;
code = '';
message = '';
obj=pullAjax();
obj.onreadystatechange=function()
{
if ( user.length < 6 || user.length > 20 )
{
x.style.border = "2px solid red";
username_msg.style.color = "red";
message = "Username contains min 6 and max 20 allowed characters";
username_msg.innerHTML = message;
found = 1; //This works properly
}
else if(obj.readyState==4)
{
eval("result = "+obj.responseText);
code = result['code'];
message = result['result'];
if(code <=0)
{
x.style.border = "2px solid red";
username_msg.style.color = "red";
found = 1; //This doesnt works and found value remain zero
}
else
{
x.style.border = "2px solid green";
username_msg.style.color = "green";
}
username_msg.innerHTML = message;
}
}
obj.open("GET",site_root+"username_check.php?username="+user,true);
obj.send(null);
return found;
}
Why found variable not working properly in if statement?
The found variable working properly in if ( user.length < 6 || user.length > 20 ) but not working in if(code <=0). why? i want to send found value via return at the end of the function username_check()
please anyone resolve this.
function pullAjax(){
var a;
try{
a=new XMLHttpRequest()
}
catch(b)
{
try
{
a=new ActiveXObject("Msxml2.XMLHTTP")
}catch(b)
{
try
{
a=new ActiveXObject("Microsoft.XMLHTTP")
}
catch(b)
{
alert("Your browser broke!");return false
}
}
}
return a;
}
function username_check()
{
var found = 0;
var x = document.getElementById('username');
var username_msg = document.getElementById('username_msg');
user = x.value;
code = '';
message = '';
obj=pullAjax();
obj.onreadystatechange=function()
{
if ( user.length < 6 || user.length > 20 )
{
x.style.border = "2px solid red";
username_msg.style.color = "red";
message = "Username contains min 6 and max 20 allowed characters";
username_msg.innerHTML = message;
found = 1; //This works properly
}
else if(obj.readyState==4)
{
eval("result = "+obj.responseText);
code = result['code'];
message = result['result'];
if(code <=0)
{
x.style.border = "2px solid red";
username_msg.style.color = "red";
found = 1; //This doesnt works and found value remain zero
}
else
{
x.style.border = "2px solid green";
username_msg.style.color = "green";
}
username_msg.innerHTML = message;
}
}
obj.open("GET",site_root+"username_check.php?username="+user,true);
obj.send(null);
return found;
}