<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>

<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY text=#000000 bgColor=#ffffff>
<DIV><SPAN class=785555722-07112006><FONT face="Comic Sans MS" color=#000080 
size=2>It was creating a new variable inside the function 
(scope).</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV align=left><FONT color=#000080 size=2>John Warner</FONT></DIV>
<BLOCKQUOTE 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000080 2px solid; MARGIN-RIGHT: 0px">
  <DIV></DIV>
  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT 
  face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> 
  javascript-bounces@LaTech.edu [mailto:javascript-bounces@LaTech.edu] <B>On 
  Behalf Of </B>Guillaume<BR><B>Sent:</B> Tuesday, November 07, 2006 5:56 
  PM<BR><B>To:</B> [JavaScript List]<BR><B>Subject:</B> Re: [Javascript] Avoid 
  multiple onclick<BR><BR></FONT></DIV>John,<BR><BR>Yep, so simple and 
  working... Thanks !!<BR>I was trying the same but with:<BR><PRE>var bInitialized = false; </PRE>Wich strangely was not 
  working.<BR>Regards.<BR>Guillaume.<BR>
  <BLOCKQUOTE cite=mid02e801c702bd$2ef8cbc0$4701a8c0@earth type="cite"><PRE wrap=""> function DoSomethingElse()
  </PRE>
    <BLOCKQUOTE type="cite"><PRE wrap="">        {
                       // Need to re-enable the function 
above to run again

                ...
    </PRE></BLOCKQUOTE><PRE wrap=""><!---->bInitialized = false;    // &lt;&lt;&lt;-------------
  </PRE>
    <BLOCKQUOTE type="cite"><PRE wrap="">        }

    </PRE></BLOCKQUOTE><PRE wrap=""><!---->
John Warner


  </PRE>
    <BLOCKQUOTE type="cite"><PRE wrap="">-----Original Message-----
From: <A class=moz-txt-link-abbreviated href="mailto:javascript-bounces@LaTech.edu">javascript-bounces@LaTech.edu</A> 
[<A class=moz-txt-link-freetext href="mailto:javascript-bounces@LaTech.edu">mailto:javascript-bounces@LaTech.edu</A>] On Behalf Of Guillaume
Sent: Tuesday, November 07, 2006 2:07 PM
To: [JavaScript List]
Subject: Re: [Javascript] Avoid multiple onclick


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

                ...
        }


    </PRE>
      <BLOCKQUOTE type="cite"><PRE wrap="">At 10/18/2006 01:59 AM, Guillaume wrote:

      </PRE>
        <BLOCKQUOTE type="cite"><PRE wrap="">So what I'd like is the functions to fire only once even if onclick
is performed multiple times.
        </PRE></BLOCKQUOTE><PRE wrap="">
One method of preventing a function from running more than 
      </PRE></BLOCKQUOTE><PRE wrap="">once is to
    </PRE>
      <BLOCKQUOTE type="cite"><PRE wrap="">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
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>