Richard Jones' Log: Double-clicking

Wed, 13 Oct 2004

Web browsers so need to filter out double-clicks on <form> submit buttons. This is just silly:

<script type="text/javascript">
submitted = false;
function submit_once() {
    if (submitted) {
        alert("Your request is being processed.\\nPlease be patient.");
        event.returnValue = 0;    // work-around for IE
        return 0;
    submitted = true;
    return 1;

(The above being code that appears in Roundup, which I've added to pretty much every system I've written that has a web form in it)

Comment by Andy on Wed, 13 Oct 2004

How about:

input type="submit" onClick="this.value='Thinking...'; this.disabled=true;

Comment by Richard on Wed, 13 Oct 2004

That's definitely shorter :)

Comment by Eugene Morozov on Fri, 15 Oct 2004

This sucks for large forms and bad links (dial-up, for example). Sometimes you click on button, it becomes disabled, and modem hangups or link stalls. Now you have to reload the page and start filling the form from scratch. This occurs rarely but occurs nevertheless.