javascript - jQuery continue form submission with selected submit button -


i'm intercepting submission of form jquery , validating few things before continuing submission. problem there multiple submit buttons different actions on page , when try call form.submit() after validation name tag of submit button lost / not sent in request-params.

my html looks this:

<input type="submit" name="publish" value="publish"> <input type="submit" name="draft" value="save draft"> 

and in coffeescript code i'm intercepting form submission with:

$('#foo-form').submit (e) ->   e.preventdefault()   form =    # work...   # callback calls form.submit() 

i'd somehow store button clicked , pass on form.submit().

add click event handler each submit button adds (or updates) hidden input values.

function store_submit_value (ev) {     var $frm = jquery(this.form);     var $input = $frm.find("input.submit_value");     if (!$input.length) {         $input = jquery("<input />")             .attr("type", "hidden")             .addclass("submit_value")             .appendto($frm);     }     $input.attr("name", this.name).val(this.value); }  jquery("#foo-form").on("click", 'input[type="submit"]', store_submit_value); 

Comments