1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Timing event infinite loop

Discussion in 'JavaScript and AJAX' started by msn90, Jul 17, 2009.

  1. msn90

    msn90 New Member

    Joined:
    Jul 17, 2009
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    hi guys,
    This is my Timing event infinite loop with stop button javascript program. it is very useful for you.

    program code

    Code:
    <html>
    <head>
    <script type="text/javascript">
    var c=0;
    var t;
    function timedCount()
    {
    document.getElementById('txt').value=c;
    c=c+1;
    t=setTimeout("timedCount()",1000);
    }
    
    function stopCount()
    {
    clearTimeout(t);
    }
    </script>
    </head>
    
    <body>
    <form>
    <input type="button" value="Start count!" onClick="timedCount()">
    <input type="text" id="txt">
    <input type="button" value="Stop count!" onClick="stopCount()">
    </form>
    <p>
    Click on the "Start count!" button above to start the timer. The input field will count forever, starting at 0. Click on the "Stop count!" button to stop the counting.
    </p>
    </body>
    
    </html>
    :cuss:
     
  2. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    Thanks for Sharing.
     
  3. Hreno

    Hreno New Member

    Joined:
    Jul 15, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    That's Javascript, not Java.

    This should go under Web Development.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83

Share This Page