Seems like a race condition.  Why not just disable the button in the
onClick? You could start a timer to re-enable it if you needed to, but
if the page redisplays then just leave it alone.

-Mike

On 4/12/06, Dan Adams <[EMAIL PROTECTED]> wrote:
> Okay, I've got the common problem where I want to prevent some users
> from double clicking submit buttons and double submitting a form. I've
> got the following script which seems to work except that it seems to
> miss one of the clicks. If you double click, it still double submits the
> form. If you triple click, however, it double submits like before but
> then you get an alert that says 'already submitted 2' meaning that
> checkSubmit() has only been called twice. Is there something I'm
> missing? Thanks.
>
> <script>
>        <input-symbol key="form" class="org.apache.tapestry.form.Form"
> required="yes" />
>
>        <let key="checkSubmit" unique="yes">checkSubmit</let>
>        <let key="submitted" unique="yes">submitted</let>
>
>        <body><![CDATA[
> var ${submitted} = false;
> var count = 0;
>
> // ensures that the form is only submitted once
> function ${checkSubmit}() {
>        var ret = true;
>        count++;
>
>        if (${submitted} == true) {
>                alert('already submitted ' + count);
>                ret = false;
>        }
>
>        ${submitted} = true;
>        return ret;
> }
>
>        ]]></body>
>
>        <initialization><![CDATA[
> Tapestry.onsubmit('${form.name}', ${checkSubmit});
>        ]]></initialization>
>
> </script>
>
> --
> Dan Adams
> Software Engineer
> Interactive Factory
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

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

Reply via email to