www.webdeveloper.com
Results 1 to 3 of 3

Thread: javascript stopwatch

Threaded View

  1. #1
    Join Date
    Dec 2009
    Posts
    4

    javascript stopwatch

    H there this is my first post! I wanted to ask if anyone could come up with something to solve my quite simple program. With the following code you can program a simple stopwatch, what I want to add is a button than when the stopwatch is stopped, and you click, that the recorded time is recorded and displayed elsewhere (without reloding)

    the code is the following...
    Code:
    <html>
    <head>
    <script type="text/javascript">
    var c=0;
    var t;
    var timer_is_on=0;
    
    function timedCount()
    {
    document.getElementById('txt').value=c;
    c=c+1;
    t=setTimeout("timedCount()",1000);
    }
    
    function doTimer()
    {
    if (!timer_is_on)
      {
      timer_is_on=1;
      timedCount();
      }
    }
    
    function stopCount()
    {
    clearTimeout(t);
    timer_is_on=0;
    }
    </script>
    </head>
    
    <body>
    <form>
    <input type="button" value="Start count!" onClick="doTimer()">
    <input type="text" id="txt">
    <input type="button" value="Stop count!" onClick="stopCount()">
    </form>
    </body>
    </html>
    I&#180;m aware im quite a newbie to all this and that my question is quite simple and maybe to vague but I hope you can help me anyways

    Cheers to you all and thanks in advance

    Trufa
    Last edited by Kor; 12-22-2009 at 05:30 AM. Reason: wrap the code [code][/code]

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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