On Time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sasimca007
    New Member
    • Sep 2007
    • 129

    On Time

    Hello friends,
    I am writing while function in javascript, when some condition equals i want to wait execution for some time of seconds. How to do that?
    I searched internet for sleep or wait method but they telling that there is no sleep or wait methods in javascript.

    So please help me, with some code if possible....... ............... .
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Use setTimeout or setInterval.

    Comment

    • RamananKalirajan
      Contributor
      • Mar 2008
      • 608

      #3
      [HTML]<html>
      <head>
      <script type="text/javascript">
      function startTime()
      {
      var today=new Date();
      var h=today.getHour s();
      var m=today.getMinu tes();
      var s=today.getSeco nds();
      // add a zero in front of numbers<10
      m=checkTime(m);
      s=checkTime(s);
      document.getEle mentById('txt') .innerHTML=h+": "+m+":"+s;
      t=setTimeout('s tartTime()',500 );
      }

      function checkTime(i)
      {
      if (i<10)
      {
      i="0" + i;
      }
      return i;
      }
      </script>
      </head>

      <body onload="startTi me()">
      <div id="txt"></div>
      </body>
      </html>[/HTML]

      With the use of setTimeout() I am refreshing the page and displaying the time every .5sec so that it seems to be dynamic clock for the users.

      Regards
      Ramanan Kalirajan

      Comment

      • sasimca007
        New Member
        • Sep 2007
        • 129

        #4
        Hi friend,
        very very thanks for coding. It is very much useful to me. Thanks once again.

        Comment

        • RamananKalirajan
          Contributor
          • Mar 2008
          • 608

          #5
          Originally posted by sasimca007
          Hi friend,
          very very thanks for coding. It is very much useful to me. Thanks once again.
          If any doubts in the future post it in the forum. I will try to help you out.

          Regards
          Ramanan Kalirajan

          Comment

          Working...