2

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

Ryan
  • 6,756
  • 13
  • 49
  • 68

2 Answers2

0

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

Homer6
  • 15,034
  • 11
  • 61
  • 81
  • What are the expected and actual behaviors of the three buttons? Could you provide a simplified pseudo code example? Thanks – Homer6 Apr 27 '11 at 01:49
  • The other two buttons do the exact same thing... the only difference is that there is some server side processing based on which of the other two submit buttons is pressed. From a JS standpoint the other two buttons do exactly the same thing which is validate the form using jquery validate plugin then submit the form if validation is successful. – Ryan Apr 27 '11 at 01:52
0

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/

karim79
  • 339,989
  • 67
  • 413
  • 406