Calling validate function on button and getting the result (true/false)
I am tr开发者_开发百科ying to do following task:
$("#btn1").click(function(){
var success = $("#myFrm").validate();
if (success == true) {
// post form through ajax
}
else{
// set focus on first field
}
});
I think you're looking for the valid()
method:
$("#btn1").click(function(){
var success = $("#myFrm").valid();
if (success == true) {
// post form through ajax
}
else{
// set focus on first field
}
});
This assumes, of course, that you've configured jQuery validate on the form in question (using $("#myFrm").validate()
).
精彩评论