jquery/jquery-mobile — Issue #3721: Multiple buttons with type=submit and same name, serialize incorrectly on second submit
Author: jsm174
Created: 2012-03-02 21:37:51+00:00
State: open

I have a form with two buttons. Each button share the same name and have different values.

Cancel
Submit

I have a jquery form submit handler:

$("#myform").submit(function() {
alert($(this).serialize());
return false;
});

If I click Cancel, I get "button1=Cancel", if I then click Submit, I get "button1=Cancel&button1=Submit"

I have logic that may have failed during the cancel and submit, so I do not want to take people away from the form.

Using Chrome, the rendered HTML for the Cancel button is:

Cancel
Cancel

When I click Cancel, it adds a hidden input field:

Cancel

Cancel

I tried to add some jquery to remove the hidden input fields after the serialize() but then no button1 entries are serialized.