timer function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Darren Showers

    #1

    timer function

    I'm running a timer function that counts down from set time frames. It has
    an odd tendency to drop 2 seconds at the beginning but then work fine the
    rest of the way. Can anyone suggest what could be happening here?


  • Evertjan.

    #2
    Re: timer function

    Darren Showers wrote on 09 nov 2004 in
    microsoft.publi c.scripting.jsc ript:
    [color=blue]
    > I'm running a timer function that counts down from set time frames.
    > It has an odd tendency to drop 2 seconds at the beginning but then
    > work fine the rest of the way. Can anyone suggest what could be
    > happening here?[/color]

    What is happening here is that you don't show us the code.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress,
    but let us keep the discussions in the newsgroup)

    Comment

    • Darren Showers

      #3
      Re: timer function

      Thank you for the unnecessary candor. Here is the code:

      function startTimer() {
      running = true;
      var now = new Date();
      start =now.getTime();
      var seconds = getSec();
      var setTime = 1000 * seconds;
      endTime = start + setTime;
      showCountDown()
      }

      function getSec() {
      var r = document.frm.ra dio1;
      for (var i=0; i<r.length; i++) {
      if (!r[i].checked) continue;
      else return r[i].value;
      }
      return null;
      }

      function showCountDown() {
      var present = new Date();
      moment = present.getTime ();
      if (endTime - moment<= 0) {
      stopTimer();
      displayTimer.in nerHTML = "TIME'S UP!";
      showTimeOver();
      } else {
      var lapse = new Date(moment - start);
      var minLapse = lapse.getMinute s();
      var secLapse = lapse.getSecond s() + 1;
      var timeLapse = minLapse;
      timeLapse += ((secLapse < 10) ? ":0" : ":") + secLapse;
      document.frm.ti meLapse.value = timeLapse;
      var delta = new Date(endTime - moment);
      var theMin = delta.getMinute s();
      var theSec = delta.getSecond s();
      theTime = theMin;
      theTime += ((theSec < 10) ? ":0" : ":") + theSec;
      document.frm.ti merDisplay.valu e = theTime;
      displayTimer.in nerHTML = theTime;

      if (running) {
      timerID = setTimeout("sho wCountDown()",1 000)
      }
      }
      }

      function stopTimer() {
      displayTimer.in nerHTML = theTime + " TIMER STOPPED";
      clearTimeout(ti merID);
      running = false;
      }


      "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
      news:Xns959CC79 8C3009eejj99@19 4.109.133.29...[color=blue]
      > Darren Showers wrote on 09 nov 2004 in
      > microsoft.publi c.scripting.jsc ript:
      >[color=green]
      > > I'm running a timer function that counts down from set time frames.
      > > It has an odd tendency to drop 2 seconds at the beginning but then
      > > work fine the rest of the way. Can anyone suggest what could be
      > > happening here?[/color]
      >
      > What is happening here is that you don't show us the code.
      >
      >
      > --
      > Evertjan.
      > The Netherlands.
      > (Please change the x'es to dots in my emailaddress,
      > but let us keep the discussions in the newsgroup)
      >[/color]


      Comment

      Working...