[Javascript] Avoid multiple onclick

Guillaume javascript at webdesignofficina.com
Tue Nov 7 13:06:39 CST 2006


Paul,

This is perfectly working... This function will work once only...
However how do I allow that function to run again once another function 
has been called ?

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

                ...
        }


        function DoSomethingElse()
        {
                       // Need to re-enable the function above to run again

                ...
        }


> 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
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>




More information about the Javascript mailing list