4 Replies Latest reply on Jul 11, 2006 8:43 AM by drforbin1970

    How to prevent double click?

    kruse Level 1
      How du I prevent a user to dubbleclick on a link and then submitting the page twice?
      I'm using the code below:


      function UpdateApplication(inc){
      document.DataForm.Inc.value=inc;
      document.DataForm.submit();
      }

      ……

      <a href="Javascript: UpdateApplication(1);" target="_self" onMouseOver="self.status='Update Application'; return true;" onMouseOut="self.status=''; return true;">
      <img src="/layout/buttons/Save.gif" alt="Update Application" border="0">
      </a>

      Any ideas?
        • 1. Re: How to prevent double click?
          monkey_woo_too Level 1
          This is what i do is this.

          <form name="formJob" id="formJob"
          [...]
          onsubmit="document.getElementById('formJob__submit').disabled=true;">
          <input class="majorBtn" id="formJob__submit" type="submit" value="Go />
          </form>

          PS
          You don't need to do this in for Firefox, only IE
          • 2. Re: How to prevent double click?
            dmuniz
            You might also want to look at Qforms by PengoWorks. It is a Javascript API that automatically includes this functionality. You also get form validation which works great.
            • 3. Re: How to prevent double click?
              kruse Level 1
              quote:

              Originally posted by: monkey woo too
              This is what i do is this.

              <form name="formJob" id="formJob"
              [...]
              onsubmit="document.getElementById('formJob__submit').disabled=true;">
              <input class="majorBtn" id="formJob__submit" type="submit" value="Go />
              </form>

              PS
              You don't need to do this in for Firefox, only IE



              This does not work.

              I guess it is because i'm using a <a href> and anot an <Input> tag.

              Any other sugestions. I think that it will be hard to prevent double clicks on a <a href>.

              I would prefere not to use a third party product. Anyway I'm not sure if their solution will work on a <a href> anyway.


              • 4. Re: How to prevent double click?
                drforbin1970 Level 1
                I believe the following will work for you. But use 'onclick' to call your Javascript function as in the example below.
                The function sets a variable as a switch. If the switch is zero the first time the link is clicked, the function sets the switch to 1 and submits the form. If the user clicks the link again, the switch has already been changed and the form is not submitted.

                <script language="JavaScript">
                dbl_stop = 0
                function UpdateApplication(inc){
                if(dbl_stop == 0){
                dbl_stop = 1;
                document.DataForm.Inc.value=inc;
                document.DataForm.submit();
                }
                }
                </script>

                <a href="javascript:void(0);" onclick="UpdateApplication(1)" target="_self" onMouseOver="self.status='Update Application'; return true;" onMouseOut="self.status=''; return true;">
                <img src="/layout/buttons/Save.gif" alt="Update Application" border="0">
                </a>