<snip>
In IE5 (which is what Id been developing with) the code caused no problems,
but in IE6 clicking the submit button would cause a natural submit to occur
AND my javascripts submit() would also work, resulting in a second request
swiftly following the first (and generally resulting in a error). Sometimes
the first request would get processed second and the page worked, other
times the second one would get processed second and so the error was
displayed. We had to tell the users to 'keey trying' until I had a chance to
fix the problem!
</snip>

I prevent double submits by using a timer.  On the first submit, the timer
is reset to prevent secondary submit attempts. To assist this, the submit
button is grayed out (disabled).  If the page hasn't gone through in 30
seconds, the grayed out button is enabled for the user try again.  Some
example code follows:

<form name="someForm" action="http://www.someUnknownWebSite.com";
onsubmit="return  submitTimer(this);">
Example text <input type="text" name="example" value="extext">
<input type="submit" name="mysubmitbutton" value="Submit Form">
</form>

<script language="javascript">
// <!--

var submitTime = new Date(0); // initialize at page load

function submitTimer(someForm) {
        var result = false;
        var now = new Date();
        var difference = now - submitTime;

        // Has at least 30 seconds passed since the submit
        // this always works the first time because we back-dated
        // the first submitTimer.
        if ( difference > 30000 ) {

                // Gray out the submit button
                someForm.mysubmitbutton.disabled = true;

                // Reset the above grayed-out submit button
                // after 30 seconds in case the user must
                // try submitting again due to no server response
                setTimeout("enableButton(document.someForm.mysubmitbutton);",30000);

                // Reset the timer to prevent double submits
                submitTime = new Date();
                result = true;
        };
        return result;
}
function enableButton(btn) {
        btn.disabled = false;
};

// -->
</script>

Note: not all browsers support the disabled property so it won't gray out on
all browsers, but the Date functions I use should still prevent multiple
submits. Feel free to add an alert("Please wait until 30 seconds has passed
to try again.") if that's your preference.

Regards,
David


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to