I've got an html form that is being validated using jquery validate plugin. The form has 3 submit buttons. Each submit button causes the page to do something a little different. I'd like for one of the three submit buttons to just submit the form and completely ignore the validation routine I've built using the jQuery validation plugin. Is this possible?
Thanks
For the submit buttons, you can unbind events on that DOM element, then bind your own function. Also, make sure that your function returns false or it will submit the form.
http://api.jquery.com/bind/
Also, see:
http://api.jquery.com/event.stopPropagation
Yes, it is possible. You test the ID of the clicked submit button, and use the click
event to perform the form submission, or the validation, depending on which button has been clicked:
$("#form input:submit").click(function(e) {
if (e.target.id == "foo") { // or this.id, or $(this).attr('id')
alert("submitting");
$(this).closest("form").submit();
} else {
alert("do the validation");
return false;
}
});
Demo: http://jsfiddle.net/karim79/VmX3R/3/
精彩评论