http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/ Iam using this form plugin.where we can call Separate function inorder to do validation
<input type="text" id ="empno " class="validate['required',FuncCall[empnos]]">
“Funccall[empnos]” which is File Jquery-validation-en.js will call separate JS function called empvalidate()
"empnos" : {
"nname":"empvalidate()",
"alertText":"* This EMP NO is not there "
},
function empvalidate(){
var empno = $("#empno").val();
if(empno!=''){
$.ajaxSetup ({cache: false});
$.getJSON("emp.php",{'param1' : $("#param1").val(),'empno' :$("#empno").val()},
function (data){
if(data['status']==="true"){
exists="true";
}else{
exists="false";
}
});
}
return exists;
}
From The above function iam not able to return true or false as it has anoymous function.
How can i return true when the status is true and vice versa.It is always returning me false
Ajax method getJSON performs asynchronously, so your method returns ‘exists’ before it requested the server for a return value.
So you need to make your ajax request as async = false, like this:
UPD: Okay, see the full version of your function:
Take care, I did not test the code above, so you need to understand the reason of each line of the code.