www.webdeveloper.com
Results 1 to 4 of 4

Thread: How do I end an onClick event?

Hybrid View

  1. #1
    Join Date
    Dec 2013
    Posts
    10

    How do I end an onClick event?

    This code calls my function and everything works almost perfectly. Perfectly, except if I try to put an alert in to inform the user when the countdown reaches zero, it keeps popping up I haven't been able to find how to turn off the function once it is called.

    <input name="startcount" type="button" onClick="setInterval('counterMod()',1000)" value="Start Countdown">

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    Code:
    var popupAlreadyShown=false;
    
    function myRepeatedFunc(){
    if(bla-bla-bla){
    if(!popupAlreadyShown){alert('Happy New Year');
    popupAlreadyShown=true;
    }
    }
    }
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  3. #3
    Join Date
    Dec 2013
    Posts
    10
    Thank you. I was looking at my function as if it was the whole program.

  4. #4
    Join Date
    Dec 2013
    Posts
    21
    I would separate your onClick from a direct setInterval call, then use clearInterval to clear the timer once used. Note: I may not have all the syntax correct but the basic idea is:

    var myVar

    <input name="startcount" type="button" onClick=function() fireTimer;

    function fireTimer()
    {
    myVar = setInterval('counterMod()',1000)" value="Start Countdown";
    }

    function counterMod()
    {
    clearInterval(myVar);
    ...your counter code....
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles