Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: dynamic clock

  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    dynamic clock

    I made a dynamic clock but it only works inside a textbox.

    <html>
    <body>The Time Is<form name="myclock">
    <input type="text" name="thebox" size="40" maxlength="256">

    </form></body><head><script type="text/javascript">
    function joshfunction(){
    var joshdate=new Date()
    hour=joshdate.getHours()
    minutes=joshdate.getMinutes()
    seconds=joshdate.getSeconds()
    var hello

    if((hour>12)){
    hour=hour-12
    hello="P.M."
    }
    else
    {
    hello="A.M."
    }
    if((hour==0))hour=12
    if((minutes<9))minutes="0"+minutes
    if((seconds<9))seconds="0"+seconds

    document.myclock.thebox.value=(hour+":"+minutes+" and "+seconds+' seconds '+hello)
    }
    </script></head><body onLoad="setInterval('joshfunction()',1000)"></body></html>




    How can i make that clock update using css without it being in a textbox?

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use a span and innerHTML instead of the form...

    Without changing to much of your code, other than what was necassary and/or removing completely redundant variables...
    Code:
    <html>
    <script type="text/javascript">
      function joshfunction(){
       var hours    = new Date().getHours();
       var minutes = new Date().getMinutes();
       var seconds = new Date().getSeconds();
    
        if(hours > 12){
           hours = hours-12;
           var hello = 'P.M.';
        }  else{ var hello =  'A.M.' };
    
        if(hours == 0)hours = 12;
        if(minutes <= 9)minutes = '0'+minutes;
        if(seconds <= 9)seconds = '0'+seconds;
    
        document.getElementById('myclock').innerHTML = hours+":"+minutes+" and "+seconds+' seconds '+hello;
        setTimeout('joshfunction()',1000);
      }
    </script>
    </head>
    
    <body onLoad="joshfunction()">
    The Time Is: <span id="myclock"></span>
    </body>
    </html>
    .......Willy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •