My return values are not working, and I am trying to validate login before form submit. I just can't put my finger on it.
function checklogin()
{
var name=$('input[name=username]').val();
var name=name.trim();
var pass=$('input[name=password]').val();
var pass=pass.trim();
if(name == '')
{
return false;
}
else
{
$.ajax({
type: 'post',
url: 'checklogin.php',
data: {
user_name:name,
user_pass:pass,
},
success: function (response) {
if(response=="OK")
{
// document.getElementById('error').innerHTML=" User pass test ok.";
console.log("Hooray, it worked!");
return true;
}
else
{
document.getElementById('error').innerHTML=" Invalid Email or Password.";
console.log("Nope... not working! "+name);
return false;
}
}
});
}
}
I did all kinds of tests and all script work but the this part just act like it always return true. it seems the Ajax part is my problem.