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

stopwatch !!!

Discussion in 'Web Design, HTML And CSS' started by gsingla4u, Apr 16, 2010.

  1. gsingla4u

    gsingla4u New Member

    Joined:
    Jul 27, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    i want to create a Stopwatch but only with "setinterval" & "setTimeout" functions ....
     
  2. satyedra pal

    satyedra pal New Member

    Joined:
    Mar 26, 2010
    Messages:
    93
    Likes Received:
    1
    Trophy Points:
    0
    Following is the Coding of stopwatch.which will generate only the seconds in the textbox and with start/stop and reset button.It's coding is written in the java script within html.
    HTML:
    <html>
    <HEAD>
    <SCRIPT LANGUAGE= "JavaScript">
    
    var sec = 0;
    var secc = 0;
    function setinterval() {
    if (secc == 0) 
    {
    secc= 1;
    a = new Date();
    a.setTime(a.getTime() - sec);
    } 
    else 
    {
    secc = 0;
    cur = new Date();
    sec= cur.getTime() - a.getTime();
    document.watch.time.value = sec ;
     }
    }
    function treset() {
    secc = 0;
    sec= 0;
    document.watch.time.value = sec ;
    }
    function display() 
    {
    setTimeout("display()", 100);
    if (secc== 1)  
    {
    cur = new Date();
    sec = cur.getTime() - a.getTime();
    document.watch.time.value = sec;
       }
    }
    </script>
    </head>
    <BODY onLoad="display()">
    
    <FORM NAME="watch">
    <input type ="text" Name="time">
    <input type="button" Name="button" VALUE="Start/Stop" onClick="setinterval()">
    <input type="button" NAME="reset" VALUE="Reset" onClick="treset()">
    </FORM>
    
    </body>
    </html>
     
    Last edited by a moderator: Apr 22, 2010
  3. gsingla4u

    gsingla4u New Member

    Joined:
    Jul 27, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    thnx a lot !!!
     

Share This Page