I’m trying to determine button was used to submit the form.
I have two buttons – cancel and submit within the form and depending on which one is clicked I want to carry out some functions before the submit happens.
I can determine the value from the POST in the server side but need to do so on the client side first
What jquery function do I call to determine if the ‘cancel’ button was used?
The submit of the form is being handled as part of the submitHandler event of jquery validation.
Here’s the elements:
<input name="submit" type="submit" value="Submit" />
<input name="cancel" type="submit" value="Cancel" />
Here’s the submit handler:
submitHandler: function(form) {
form.submit();
}
Thanks
You are correct by not wanting to use external or additional
clickhandlers with the jQuery Validate plugin since the plugin already automatically captures thesubmitclickevent with itssubmitHandlercallback.Your problem is that you do not really have a “cancel” button. This is nothing more than a duplicate
submitbutton…No matter what you do, the plugin is always going to treat its
clickevent as a regular form submit. What if you change it into a<button></button>? Still no good. The plugin also treats thebutton‘sclickevent as a regular form submit. There is no other callback function/option built-in to this plugin that can capture any other kind of button/cancelclickevent.Your only option is to place it outside of your
<form></form>tags. The Valdiate plugin will not see it and you can then bind your ownclickevent to it.Your own
cancelclick event:Demo using
<input type="submit": http://jsfiddle.net/wZwcQ/Demo using
<button></button>: http://jsfiddle.net/h7XKc/