javascript - Discover which form button triggered submission -
in form, have 2 submit buttons.
<input type="submit" name="save" value="save draft"/> <input type="submit" name="send" value="start sending" />
now before submitting form server, want perform specific tasks depending on button clicked.
$('form').submit(function(){ if submit equals save task 1; elseif submit equals send task 2 }
how check button pressed?
$(":submit").click(function() { $("form").data("submit-button", this.name); }); $("form").submit(function() { var button = $(this).data("submit-button"); ... });
add click handler on submit buttons stores name. extract name in submit handler.
Comments
Post a Comment