How to prevent form from submitting multiple times from client side?

omg picture omg · May 29, 2009 · Viewed 135.6k times · Source

Sometimes when the response is slow, one might click the submit button multiple times.

How to prevent this from happening?

Answer

vanstee picture vanstee · May 29, 2009

Use unobtrusive javascript to disable the submit event on the form after it has already been submitted. Here is an example using jQuery.

EDIT: Fixed issue with submitting a form without clicking the submit button. Thanks, ichiban.

$("body").on("submit", "form", function() {
    $(this).submit(function() {
        return false;
    });
    return true;
});