G'day Guys
My issue SHOULD be pretty basic but I'm not sure whats going on.
I found I can only RETURN a value if I return it from the "root" of the function. For example, if I type "if(x==1){ return true; }" it doesn't want to return a value becuase its within an if..
Anyways this is my exact issue:
So I call usercheck() from onsubmit on my form.HTML Code:<form action="login.php" onsubmit="return usercheck('username', 'password', 'login');" method="post" name="login" id="login">
The alert(returner); returns back undefined.Code:function usercheck(user, pass, form){ var user = document.getElementById(user).value; var pass = document.getElementById(pass).value; var queryStr = 'username=' + escape(user) + '&password=' + escape(pass); // this is a URL variable to the php // var strURL = 'ajax/usercheck.php?' + queryStr; xmlHttpReq.open('POST', strURL, true); xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttpReq.send(null); xmlHttpReq.onreadystatechange = function returner(){ if(xmlHttpReq.readyState == 4){ var response = xmlHttpReq.responseText; if(response == 0){ alert("The information you have entered is incorrect."); return false; } else { return true; } } } returner = returner(); alert(returner); return returner; }
If I type return true; UNDER the closing bracket of the xmlHttpReq.readyState == 4 if, then the alert box returns true...
So very confused 4 hours AFTER I started working on this issue.
Thanks alot to anyone that can help


Reply With Quote
Bookmarks