Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 

 2 Answer(s)

  • Hi Manish,
    Please go through the link
    Javascript Timer

    Also, here I am writing some code to create a simple Timer StopWatch you can modify it as per your requirement.
    Code:

    Script:
    window.onload = function()
    {
      stopwatch('Start');
    }
    var sec = 0;
    var min = 0;
    var hour = 0;
    function stopwatch(text) {
       sec++;
      if (sec == 60) {
       sec = 0;
       min = min + 1; }
      else {
       min = min; }
      if (min == 60) {
       min = 0; 
       hour += 1; }
    
    if (sec<=9) { sec = "0" + sec; }
       document.clock.stwa.value = ((hour<=9) ? "0"+hour : hour) + " : " + ((min<=9) ? "0" + min : min) + " : " + sec;
    
      if (text == "Start") { document.clock.theButton.value = "Stop "; }
      if (text == "Stop ") { document.clock.theButton.value = "Start"; }
    
      if (document.clock.theButton.value == "Start") {
       window.clearTimeout(SD);
       return true; }
    SD=window.setTimeout("stopwatch();", 1000);
    }
    
    function resetIt() {
      sec = -1;
      min = 0;
      hour = 0;
      if (document.clock.theButton.value == "Stop ") {
      document.clock.theButton.value = "Start"; }
      window.clearTimeout(SD);
     }
    
    
    var c=0
    var t
    function stopCount()
    {
    clearTimeout(t)
    }
    function timedCount()
    {
    document.getElementById('txt').value=c
    c=c+1
    if(c==61)
    {
    alert("time over")
    stopcount()
    }
    t=setTimeout("timedCount()",1000)
    }
    
    HTML:
    < form>
     < input type="text" id="txt">
     < input type="button" value="Start stopwatch" onClick="timedCount()">
     < p>Click on the Start button above to start the stopwatch.
    
    
    Script:
    var time = 0,
        elapsed = '0.0';
    window.setInterval(function()
    {
        time += 100;
        elapsed = Math.floor(time / 100) / 10;
        if(Math.round(elapsed) == elapsed) { elapsed += '.0'; }
        document.title = elapsed;
    }, 100);
    
  • Hi Manish,

    Use the below code for Solution.

    <span id="countdown">01:30:10</span>
    <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
    <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
    <script type="text/javascript">
        (function(){
      $(document).ready(function() {
          var time = "01:30:10",
          parts = time.split(':'),
          hours = +parts[0],
          minutes = +parts[1],
          seconds = +parts[2],
          span = $('#countdown');
    
        function correctNum(num) {
          return (num<10)? ("0"+num):num;
        }
    
        var timer = setInterval(function(){
            seconds--;
              if(seconds == -1) {
                seconds = 59;
                  minutes--;
    
                  if(minutes == -1) {
                    minutes = 59;
                      hours--;
    
                      if(hours==-1) {
                      alert("timer finished");
                      clearInterval(timer);
                      return;
                    }
                }
            }
              span.text(correctNum(hours) + ":" + correctNum(minutes) + ":" + correctNum(seconds));
        }, 1000);
      }); 
    })()
    
    </script>
    
Sign In
                           OR                           
                           OR                           
Register
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: