How to use two buttons to submit a form where one button does not run all functions
I have seen many similar questions on here but can't find one that addresses this particular issue.
I am using the jQuery Validation plugin and the form plugin. I want to have one submit button run a function after the submission is complete. But I want the other submit button to skip the last function. Any suggestions on how to do this?
Here's the code:
$("#applicant-form").validate({
submitHandler: function(form) {
$(form).ajaxSubmit({
type: "POST",
//...
error: function() {alert("error!");},
success: function() {alert("success!");},
complete: fu开发者_如何学Cnction(e) {
//function not to run with second submit goes here
}
});
return false;
},
errorPlacement: function(error,element) {
return true;
},
//...
});
I want the second submit button to stop right before the complete function starts.
maybe you can take advantage of arguments.callee.caller.toString()
to establish which function is calling the submit function and if it is a particular caller then you run the function
Try something like this:
$("#applicant-form").validate({
submitHandler: function(form) {
var submit = this.submitButton; //find submit button that is pressed
$(form).ajaxSubmit({
complete: function(e) {
if(submit.value==??????){
//function not to run with second submit goes here
}
}
});
You can identify which submit button is pressed and then decide in the complete function whether the body shoudl be executed or skipped based on the some attribute of the submit button.
精彩评论