Prevent double submission of forms in jQuery

Posted by Adam on Stack Overflow See other posts from Stack Overflow or by Adam
Published on 2010-05-13T21:45:02Z Indexed on 2010/05/13 21:54 UTC
Read the original article Hit count: 172

I have an form that takes a little while for the server to process. I need to ensure that the user waits and does not attempt to resubmit the form by clicking the button again. I tried using the following jQuery code:

<script type="text/javascript">
$(document).ready(function(){
    $("form#my_form").submit(function(){
      $('input').attr('disabled','disabled');
      $('a').attr('disabled','disabled');
       return true;
        })
    });
</script>

When I try this in Firefox everything gets disabled but the form is not submitted with any of the POST data it is supposed to include. I can't use jQuery to submit the form because I need the button to be submitted with the form as there are multiple submit buttons and I determine which was used by which one's value is included in the POST. I need the form to be submitted as it usually is and I need to disable everything right after that happens.

Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery