digital clock

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 511475
    New Member
    • Nov 2006
    • 9

    #1

    digital clock

    Hi: I am an retired school teacher who went back to school for the fun of it. my subjects were computer hardware. I am taking a course in javascript and it is about to get the better of me. I need some help with is this one. I got it to validate. But something is wrong with the logic maybe. It bombs out on object expected .
    Please give me some input. thanks
    <?xml version="1.0" encoding="utf-8" ?>
    <!DOCTYPE html PUBLIC
    "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title>Digita l Clock</title>
    <script type="text/javascript">
    <!-- HIDE FROM INCOMPATIBLE BROWSERS
    function curTime() {
    var now = new date();
    var day = now.GetDay();
    var date = now.GetDate();
    var year = now.GetFullYear ();
    var month = now.GetMonth();
    var hours = now.GetHours() + 1;
    var minutes = now.GetMinutes( );
    var seconds = now.GetSeconds( );
    var days = new Array();
    days[0] = "Sunday"; days[1] = "Monday"; days[2] = "Tuesday";
    days[3] = "Wednesday" ; days[4] = "Thursday"; days[5] = "Friday";
    days[6]="Saturday";
    var display = days[day] + " " + month + "/" + date + "/"
    + year + " "+ hours + ":" + minutes + ":" + seconds;
    document.forms[0].Readout.value = display;
    }
    var tick = setInterval("cu rTime()", 1000);
    // STOP HIDING FROM INCOMPATIBLE BROWSERS --></script></head>
    <body>
    <form action="">
    <p><input type="text" size="30" name="readout" /></p>
    </form>
    </body>
    </html>
  • Luongo
    New Member
    • Oct 2006
    • 22

    #2
    I doubt this will solve the problem, but make sure the cases are matching. Your input name is "readout" but you're calling it as "Readout".

    Comment

    • Luongo
      New Member
      • Oct 2006
      • 22

      #3
      Furthermore, I believe you'll have to call the function when the page is loaded, ie body onLoad="CurDate ()"... sorry I can't actually play around with it right now but I think that would be needed....

      Comment

      • AricC
        Recognized Expert Top Contributor
        • Oct 2006
        • 1885

        #4
        Code:
        <!-- Adjust the placement of the clock in the line below -->
        <span id="pendule"></span>
        <script language="javascript" type="text/javascript">
        <!--
        function clock() {
        var digital = new Date();
        var hours = digital.getHours();
        var minutes = digital.getMinutes();
        var seconds = digital.getSeconds();
        var year = digital.getFullYear();
        var day = digital.getDay();
        
        var month = new Array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec")
        var day = new Array ("Sun","Mon","Tues","Wed","Thurs","Fri","Sat")
        var amOrPm = "AM";
        if (hours > 11) amOrPm = "PM";
        if (hours > 12) hours = hours - 12;
        if (hours == 0) hours = 12;
        if (minutes <= 9) minutes = "0" + minutes;
        if (seconds <= 9) seconds = "0" + seconds;
        dispTime = day[digital.getDay()] + "." + " " + month[digital.getMonth()] + " " + digital.getDate() + "," + " " + year + " ";
        dispTime = dispTime + hours + ":" + minutes + ":" + seconds + " " + amOrPm;
        document.getElementById('pendule').innerHTML = dispTime;
        setTimeout("clock()", 1000);
        }
        window.onload=clock;
        // -->
        </script>

        Comment

        • AricC
          Recognized Expert Top Contributor
          • Oct 2006
          • 1885

          #5
          Sorry missed the Edit timeout. This is one I've used for quite some time if need be I can make yours work, but nosense re-inventing the wheel.


          HTH,
          Aric

          Comment

          Working...