• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Disable Button

 
Steve Watson
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a form on a JSP that sometimes takes a few seconds to save data to the database. If the user clicks the button a second time bad things can happen. How can I disable the button after it is first clicked until the form action is complete?

Code snippet:

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65217
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your web app should be written to handle such situations, but it's also a good idea to disallow the user from getting themselves into trouble in the first place.

To disable a button simply set its disabled property to true.
 
Esteban Puertas
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you can consider using the post/redirect/get pattern instead of trying to disable the user button.

Post/Redirect/Get
Redirect after post

This pattern prevents the user from sending more than one time the form data.

Hope this helps.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you're using Struts which, I believe, has a built in mechanism for implementing the Synchronizer Token pattern which is also a way to avoid the double submit problem.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65217
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Esteban Puertas:
Maybe you can consider using the post/redirect/get pattern instead of trying to disable the user button.
PRG helps mostly with double posts due to the refresh button rather than double-clicking.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic