0

Possible Duplicate:
Multiple submit Button click problem?

Have a type=Submit button in a JSP. Requirement is to disable this button on click. The basic requirement is to stop posting multiple requests of the same form if this button is clicked multiple times for the same form.

Thank You.

Community
  • 1
  • 1
user1616423
  • 15
  • 1
  • 7
  • 1
    possible duplicate: http://stackoverflow.com/questions/3967287/multiple-submit-button-click-problem?rq=1 which is already a duplicate of http://stackoverflow.com/questions/50426/preventing-accidental-double-clicking-on-a-button – Dirk Sep 05 '12 at 13:02

3 Answers3

0

Even if you disable the submit button the user can still submit the form by pressing F5 or ctrl+F5 or even using Browser reload button.So disabling the submit button won't be of much use.

Why not use Post/Redirect/Get method.

The PRG pattern basically redirects the user to another page when it is Posted.

Hence now when the user reloads or tries to resubmit the form he is calling the Get method so the form is prevented from resubmission.

However this is also not fully secured approach.

Priyank Patel
  • 6,898
  • 11
  • 58
  • 88
  • Good solution, but until the redirect comes back, the user can click again and again. I know of some users who treat web pages like their windows desktop - double clicking everytime. – f_puras Sep 05 '12 at 13:10
  • yes, there is already some PRG but by the time the redirect happens, i want to disable it. – user1616423 Sep 05 '12 at 13:17
0

Look here: http://www.developertutorials.com/tutorials/javascript/how-disable-submit-button-050416-1275/

Wes
  • 42
  • 5
  • 1
    It is always a good practice to give a summary or the main points in the links you are posting, since if the website goes down or the article is removed from the website the link you gave becomes useless and hence your answer becomes utterly useless. If you have specified the gist of the link then your answer still remains valid and useful. Thanks – Prakash K Sep 05 '12 at 13:38
0

I use a simple JS function you can invoke with onlick():

<script type="text/javascript">
    var isSubmitted = false;

    function safeSubmit(entityName) {
        if (!isSubmitted) {
            isSubmitted = true;
            document.forms[0].submit;
        }
    }
</script>
f_puras
  • 2,521
  • 4
  • 33
  • 38