mike's web log

 

Blog Search


(Supports AND)

 

Google Ads

 

Feed

Subscribe to the RSS feed for this blog.

See this post for info on full versus truncated feeds.

 

Quote

One likes to think that literature has the power to render comprehensible different kinds of unhappiness. If it can't do that, what's it good for?

Elif Batuman



 

Navigation






<May 2013>
SMTWTFS
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678


 

25 Most-Visited Entries

 

Categories

  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
  RSS
 

Blogs I Read

 

Contact

Email me
 

Blog Statistics

Dates
First entry - 6/27/2003
Most recent entry - 4/9/2013

Totals
Posts - 2293
Comments - 2463
Hits - 1,528,505

Averages
Entries/day - 0.63
Comments/entry - 1.07
Hits/day - 422

Update every 30 minutes. Last: 1:04 AM Pacific

 
   |  Double submit redux

posted at 06:07 PM | | [4] |

A little while ago, I messed around with ways to disable a submit button so that it didn't double post. The example I had worked ok, in that it was impossible to click the button twice, because as soon as it had been clicked, it disappeared. However, what I really wanted was to just disable the button. Unfortunately, using client script to disable the button also cancelled the post.

This came up yet again at work, and once again Carlos Aguilar had a clever answer. He discovered an interesting trick: rather than disabling the submit button immediately, you can use window.setTimeout() to set a short interval (zero seems to work) before invoking a method that disables the button. I'm assuming that the script has to "release" in order for the post to work, and using a short timeout accomplishes this.

Starting with the code from the original post, I changed the client code to this:
function disableButton()
{
window.setTimeout('disableAfterTimeout()',0);
}

function disableAfterTimeout()
{
document.form1.SafeButton.disabled = true;
}
You can see the effect in this test page:

Double post (with disable)

Carlos's original example was much more clever; he uses server code to build up a list of controls that should be disabled in this way. He also noted that if the user clicks the browser's Stop button, the disabled controls stay disabled. Cure: don't do that, heh.

Update I also did some experimentation with using a GUID to track the uniqeness of each postback. See details in this post.

[categories]