Stopping double clicking with Perl CGI

David Dorward david at
Thu May 22 10:49:51 BST 2008

On 22 May 2008, at 10:17, Chris Jack wrote:

> I thought I'd be a disruptive element in the group and ask a Perl  
> question.
> What is the best way of stopping a user double clicking a button in  
> a web page created using Perl CGI?

Since Perl (via CGI) runs on the server, it can't stop the user  
clicking multiple times. You need something which runs in the browser,  
which means JavaScript.

Now you could do something along the lines of:

YAHOO.util.Event.addListener("myForm", "submit", function(e){
	if (this.submitted) {
		// That's a bad class name used here to make it clear what it does.
  		// You should use a better one in your code
		return false;
	this.elements['mySubmitButton'].className = 'dimmed-submit-button- 
	this.submitted = true;

(I use a library. It saves me effort. 

However, this results in the situation where, due to the wonders of  
networks, the browser might not manage to send its request or get a  
response back properly leaving the user with a dead form (not often,  
but it is annoying when it happens).

As Smylers pointed it, it also screws up the back button.

If you go down this route you should probably add a timer to turn it  
back on if it looks like it failed, and an onDOMReady event to turn it  
back on when the user hits the back button.

A  better solution would probably be to examine the data on the server  
and ignore duplicate submissions (or treat them as updates).

David Dorward

More information about the mailing list