How to return value for form validation using callback function? This is not working for me..
<form action="loggedin.php" onsubmit="return test(valid)" method="post">
function test(callback) {
var k = "";
var httpRequest = new XMLHttpRequest();
httpRequest.onload = function(){
k = callback(httpRequest.responseText);
return k;
};
httpRequest.open("POST", "check.php",true);
var a = document.getElementById("email").value;
var b = document.getElementById("pwd").value;
httpRequest.send("email=" + a + "&passwd=" + b);
}
function valid(resp){
alert(resp); // resp is correctly defined here
if(resp == "Correct"){
return true;
}
else{
return false;
}
}
I need to validate the form data using ajax response.. I want to return true or false to form onsubmit method.. Can callback functions return value?