[Javascript] Avoid multiple onclick

Paul Novitski paul at juniperwebcraft.com
Wed Oct 18 04:23:16 CDT 2006


At 10/18/2006 01:59 AM, Guillaume wrote:
>So what I'd like is the functions to fire only once even if onclick 
>is performed multiple times.


One method of preventing a function from running more than once is to 
set a global variable the first time the function is called, and 
refuse to run if that variable is set:

         var bInitialized = false;
         ...
         function DoSomething()
         {
                         if (bInitialized) return;
                 bInitialized = true;

                 ...
         }

Regards,
Paul 




More information about the Javascript mailing list