I have written a script register user. And in the last step I need value true or false from a function to find that email is already existed or not.
function do_register(user_email){
if (!isemailexist(user_email)) {
document.getElementById("error").innerHTML="email is already exist, please change!!";
document.regForm.user_email.focus()
return false;
}
if (user_email=="") {
document.getElementById("error").innerHTML="email is emphy!!";
document.regForm.user_email.focus()
return false;
}
if(document.regForm.user_name.value!=""){ process_register();} }
function isemailexist ()
xmlHttp.onreadystatechange=function () {
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
var str=xmlHttp.responseText;
var res=JSON.parse(str);
if (res[0]=="no"){
return false;
}
}
haha=xmlHttp.onreadystatechange.test(res[0]); ///I used test(); methode in order to find value true or false
}
I have tried alot but none of them could give me true or fals !
I have updated my script above, I hope it´s better. Some more code:
PHP CODE
if(mysql_num_rows($result)>0){ // email is already exist
$phpArray = array("no","Erroremail is aleady exist");
echo json_encode($phpArray);
}