I want to implement a functionality of changing user's password. It's basically a form with three fields. the ids of the three input are oldpassword , and newPassword and newPasswordAgain .
When the user lost focus of the oldpassword input or submit the form , I want to check against the database , to see if the oldpassword is correctly entered. How can I achieve this by using jquery validation ?
I add a custom rule like this :
$.validator.addMethod("checkOldPass",function (value ,element) {
var validPass = false ;
$.post("/SMS/admin/users/checkOldPass.do" , {"empId":empId , "oldEmpPass":$.md5(value)},function (data) {
var msg = eval('('+data+')');
if(msg.resultFlag == 1) {
validPass = true ;
}
});
return validPass ;
} , "error!");
But the problem is , before my post method returns a result flag , the method already finished , so I always get the error message . I know jquery validation has a remote method ,but I can't use it, because I am using struts2-json plugin , my json result always encapsulate in a object , and remote method need a boolean json result . I can't directly get true or false from the result .