Execute some functions without submit and then submit
I have two inputs the must be validate on submit. I'm trying this:
$("#phase1_form").submit(function(e){
var result1 = $("#phase1_respo开发者_StackOverflownsVibleByFirstSignOff").isValid();
var result2 = $("#phase1_responsibleBySecondSignOff").isValid();
if ((result1
&& result2
))
{
return true;
}
});
But the "isValid" function is not so fast and the form is submitted. I though that maybe I could use the "preventDefault" method, but I have no idea how to "cancel" the effect of this method after the "isValid" function returns some result.
Thanks
It's not about the speed of the isValid
function, the submit will definitely wait for the result. The problem is that you only return true
or undefined
, but you need to return false
to stop the form from submitting:
$("#phase1_form").submit(function(e){
var result1 = $("#phase1_responsVibleByFirstSignOff").isValid();
var result2 = $("#phase1_responsibleBySecondSignOff").isValid();
return result1 && result2;
});
精彩评论