My current implementation involves utilizing Ajax and Php for user login validation. Unfortunately, the form onsubmit function is not properly functioning.
<form action="loggedin.php" onsubmit="return test()" method="post">
Below is the corresponding Javascript code:
function test(){
var a = document.getElementById("email").value;
var b = document.getElementById("pwd").value;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
var resp = this.responseText;
if(resp != "Correct"){
document.getElementById("email").value = "";
document.getElementById("pwd").value = "";
document.getElementById("passdiv").style.display = "block";
return false;
}
else{
return true;
}
}
else{
return false;
}
};
xmlhttp.open("POST","check.php",true);
xmlhttp.send("email=" + a + "&passwd=" + b);
}
Can anyone shed light on why the onsubmit function is not working as intended?