How to treat the submission of a form to be executed only once?

Asked

Viewed 441 times

3

In a Method POST form , when I click the button twice quickly it executes the submission twice.

Solutions with javascript or spring framework .

1 answer

10


Disable the button after the first click, because if the request delay the user will have the perception that the request was really sent, and can not send another.

$('form#id').submit( function( e ) {
  $( this ).children( 'input[type=submit]' ).attr( 'disabled', 'disabled' );
  e.preventDefault(); 
  return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="id">
  <input type="submit"/>
</form>

  • Thanks for the feedback. It’s a good solution

  • 2

    @David, very good solution! It would be nice for you to edit the post by adding the code so that if the jsfiddle link breaks more people they can be helped :D

  • 1

    Okay, I’ve been edited, thanks for the tip.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.