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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Live Clock - Javascript

    I am using a script from hotscripts.com that uses javascript to display a live updating digital style clock.

    Here is the javascript code that generates the data:

    Code:
    <script type="text/javascript">
    
    function live_clock()
         {
             var today  = new Date();
             var second = today.getSeconds();
             var minute = today.getMinutes();
             var hour   = today.getHours();
             var hour24 = today.getHours();
             var ampm   = "";
    		 var zone	= today.
             
             var day    = today.getDay();
             var date   = today.getDate();
             var month  = today.getMonth();
             var year   = today.getFullYear();
             
             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 mns   = new Array();
              mns[0]   = "January";
              mns[1]   = "February";
              mns[2]   = "March";
              mns[3]   = "April";
              mns[4]   = "May";
              mns[5]   = "June";
              mns[6]   = "July";
              mns[7]   = "August";
              mns[8]   = "September";
              mns[9]   = "October";
              mns[10]  = "November";
              mns[11]  = "December";
               
            if(second<10)
                {
                    second = "0"+second;
                }
                
            if(minute<10)
                {
                    minute = "0"+minute;
                }
                
            if(hour24<=12)
                {
                    ampm = "AM";
                }
                
            else
                {
                    ampm = "PM"
                }
                
            if(hour24>=12 && hour24>=13)
                {
                    hour= hour-12;
                }
                
            if(hour24==0)
                {
                    hour=12;
                }
            
            document.getElementById('live_clock').innerHTML=(days[day]+', '+date+' '+mns[month]+' '+year+' '+hour+":"+minute+":"+second+' '+ampm+' PST');
        
    	}
    </script>
    I store that code in a seperate file and require it through php:

    PHP Code:
    <?php require_once('includes/clock.php'); ?>
    Then I place a div inside the page wherever I want the clock to display using:

    PHP Code:
    <div id="live_clock" name="live_clock" class="date">&nbsp;</div

    Works fine in Firefox however not showing up in IE 6.0, the example on site works but not in my page.

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    This line is incomplete and does IE in and should cause an error in FF
    Code:
    var zone	= today.
    since you do not use 'zone' any where in your script you do not need it

  • #3
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Proof read for the win! I guess just because it works in Firefox doesn't mean the code is all good That was an easy one to spot, I apologize.


  •  

    Posting Permissions

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