Loading ...
Sorry, an error occurred while loading the content.
 

countdown clock

Expand Messages
  • ohippieme
    I m looking for someone who can help me out with a countdown Clock.. I have searched the internet and found bunch s of them, but I can t get any to work. I
    Message 1 of 4 , Nov 11, 2006
      I'm looking for someone who can help me out with a countdown Clock..
      I have searched the internet and found bunch's of them, but I can't
      get any to work. I even used the book for my class in Javascript and
      that wouldn't work. I'm missing something??
      Can anyone tell me why this doesn't work.

      <SCRIPT LANGUAGE="JavaScript">

      var timerID = null;
      var timerRunning = false;
      function stopclock (){
      if(timerRunning)
      clearTimeout(timerID);
      timerRunning = false;
      }
      function showtime () {
      var now = new Date();
      var hours = now.getHours();
      var minutes = now.getMinutes();
      var seconds = now.getSeconds()
      var timeValue = "" + ((hours >12) ? hours -12 :hours)
      if (timeValue == "0") timeValue = 12;
      timeValue += ((minutes < 10) ? ":0" : ":") + minutes
      timeValue += ((seconds < 10) ? ":0" : ":") + seconds
      timeValue += (hours >= 12) ? " P.M." : " A.M."
      document.clock.face.value = timeValue;
      timerID = setTimeout("showtime()",1000);
      timerRunning = true;
      }
      function startclock() {
      stopclock();
      showtime();
      }

      </SCRIPT>

      <body>
      <FORM name="clock">
      <input type="text" name="showtime ()" size="13" value=startclock()>
      </FORM>
      </body>
      </html>
    • Jay Lockie
      I modified your code (see below) a bit and it works (sort of) Good luck. These timers are a bit tricky. Jay Lockie ======================
      Message 2 of 4 , Nov 13, 2006
        I modified your code (see below) a bit and it works (sort of)
        Good luck. These timers are a bit tricky.
        Jay Lockie
        ======================
        <html>
        <head>
        <SCRIPT LANGUAGE="JavaScript">
        // Problems:
        // 1. No <html> nor <head> nor </head>
        // 2. text elements can't create a starting event
        // 3. The clock increments, but you can take it from here...
        // Jay Lockie
        var timerID = null;
        var timerRunning = false;
        function stopclock (){
        if(timerRunning)
        clearTimeout( timerID);
        timerRunning = false;
        }
        function showtime () {
        var now = new Date();
        var hours = now.getHours( );
        var minutes = now.getMinutes( );
        var seconds = now.getSeconds( )
        var timeValue = "" + ((hours >12) ? hours -12 :hours)
        if (timeValue == "0") timeValue = 12;
        timeValue += ((minutes < 10) ? ":0" : ":") + minutes
        timeValue += ((seconds < 10) ? ":0" : ":") + seconds
        timeValue += (hours >= 12) ? " P.M." : " A.M."
        document.all.myshowtime.value = timeValue;
        timerID = setTimeout(" showtime( )",1000);
        timerRunning = true;
        }
        function startclock() {
        stopclock();
        showtime();
        }
        </SCRIPT>
        </head>
        <body>
        <FORM name="clock" >
        <button onclick="startclock()">StartClock</button>
        <input type="text" name="myshowtime" size="13" value="0:00">
        </FORM>
        </body>
        </html>
        ======================
        ohippieme <ohippieme@...> wrote:
        I'm looking for someone who can help me out with a countdown Clock..
        I have searched the internet and found bunch's of them, but I can't
        get any to work. I even used the book for my class in Javascript and
        that wouldn't work. I'm missing something??
        Can anyone tell me why this doesn't work.

        <SCRIPT LANGUAGE="JavaScript">

        var timerID = null;
        var timerRunning = false;
        function stopclock (){
        if(timerRunning)
        clearTimeout(timerID);
        timerRunning = false;
        }
        function showtime () {
        var now = new Date();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds()
        var timeValue = "" + ((hours >12) ? hours -12 :hours)
        if (timeValue == "0") timeValue = 12;
        timeValue += ((minutes < 10) ? ":0" : ":") + minutes
        timeValue += ((seconds < 10) ? ":0" : ":") + seconds
        timeValue += (hours >= 12) ? " P.M." : " A.M."
        document.clock.face.value = timeValue;
        timerID = setTimeout("showtime()",1000);
        timerRunning = true;
        }
        function startclock() {
        stopclock();
        showtime();
        }

        </SCRIPT>

        <body>
        <FORM name="clock">
        <input type="text" name="showtime ()" size="13" value=startclock()>
        </FORM>
        </body>
        </html>






        ---------------------------------
        Check out the all-new Yahoo! Mail beta - Fire up a more powerful email and get things done faster.

        [Non-text portions of this message have been removed]
      • Jonas Raoni
        ... It doesn t make sense, you can t call functions this way. You must attach them to an event or call directly.
        Message 3 of 4 , Nov 13, 2006
          On 11/12/06, ohippieme <ohippieme@...> wrote:
          > <input type="text" name="showtime ()" size="13" value=startclock()>

          It doesn't make sense, you can't call functions this way. You must
          attach them to an event or call directly.

          <input onchange="function()" ....

          input.onchange = function;

          or just:

          <script>
          function();
          </script>


          --
          Jonas Raoni Soares Silva
          http://www.jsfromhell.com
        • Ernesto Mendoza Blanco
          clock var timerID = null; var timerRunning = false; function stopclock (){ if(timerRunning)
          Message 4 of 4 , Nov 13, 2006
            <html>
            <head>
            <title>clock</title>

            <SCRIPT LANGUAGE="JavaScript">

            var timerID = null;
            var timerRunning = false;
            function stopclock (){
            if(timerRunning)
            clearTimeout(timerID);
            timerRunning = false;
            }
            function showtime () {
            var now = new Date();
            var hours = now.getHours();
            var minutes = now.getMinutes();
            var seconds = now.getSeconds()
            var timeValue = "" + ((hours >12) ? hours -12 :hours)
            if (timeValue == "0") timeValue = 12;
            timeValue += ((minutes < 10) ? ":0" : ":") + minutes
            timeValue += ((seconds < 10) ? ":0" : ":") + seconds
            timeValue += (hours >= 12) ? " P.M." : " A.M."
            document.getElementById('showtime_input').value = timeValue;//here u update
            the input
            timerID = setTimeout("showtime()",1000);
            timerRunning = true;
            }
            function startclock(){
            stopclock();
            showtime();
            }

            </SCRIPT>
            </head>
            <!--
            the trick is here, were u tell the clock to start when the page loads.
            -->
            <body onload="startclock()">
            <!--
            note that it's better to to set the onload handler in the javascript, like
            window.onload = function(){
            //do sth
            }instead of using the 'onload' attribute of the body
            -->
            <FORM name="clock">
            <input type="text" name="showtime_input" id="showtime_input" size="13"
            value=""><!-- and here, where u set an input to display the time -->
            </FORM>
            </body>
            </html>

            On 11/12/06, ohippieme <ohippieme@...> wrote:
            >
            > I'm looking for someone who can help me out with a countdown Clock..
            > I have searched the internet and found bunch's of them, but I can't
            > get any to work. I even used the book for my class in Javascript and
            > that wouldn't work. I'm missing something??
            > Can anyone tell me why this doesn't work.
            >
            > <SCRIPT LANGUAGE="JavaScript">
            >
            > var timerID = null;
            > var timerRunning = false;
            > function stopclock (){
            > if(timerRunning)
            > clearTimeout(timerID);
            > timerRunning = false;
            > }
            > function showtime () {
            > var now = new Date();
            > var hours = now.getHours();
            > var minutes = now.getMinutes();
            > var seconds = now.getSeconds()
            > var timeValue = "" + ((hours >12) ? hours -12 :hours)
            > if (timeValue == "0") timeValue = 12;
            > timeValue += ((minutes < 10) ? ":0" : ":") + minutes
            > timeValue += ((seconds < 10) ? ":0" : ":") + seconds
            > timeValue += (hours >= 12) ? " P.M." : " A.M."
            > document.clock.face.value = timeValue;
            > timerID = setTimeout("showtime()",1000);
            > timerRunning = true;
            > }
            > function startclock() {
            > stopclock();
            > showtime();
            > }
            >
            > </SCRIPT>
            >
            > <body>
            > <FORM name="clock">
            > <input type="text" name="showtime ()" size="13" value=startclock()>
            > </FORM>
            > </body>
            > </html>
            >
            >
            >



            --
            Ernesto


            [Non-text portions of this message have been removed]
          Your message has been successfully submitted and would be delivered to recipients shortly.