Stopping double clicking with Perl CGI

David Dorward david at dorward.me.uk
Thu May 22 11:31:25 BST 2008


On 22 May 2008, at 11:18, Adam Bernard wrote:

>> For bonus points, figure out how to re-enable the button after a few
>> seconds, so that if the submit hangs and drops out they can try
>> resubmitting it.  (I have no idea if that's possible, but it would  
>> be a
>> neat solution to the main annoying problem with self-disabling submit
>> buttons)
>
> <input id="a" type="submit" onclick="this.disabled =
> true;setTimeout('document.getElementById(\'a\').disabled =
> false;',2000);" />
> seems to work.


eval() (and passing a string to setTimeout is an eval) considered  
harmful. There's no need for an id in this instance either.

onclick="this.disabled=true;setTimeout(function(foo){return function() 
{foo.disabled=false}}(this)
,2000);"

-- 
David Dorward
http://dorward.me.uk/
http://blog.dorward.me.uk/




More information about the london.pm mailing list