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 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question Count Down and Local Time

    Hellooo guys
    Can you please help?
    I've got Count Down to the race (for instance) and local time which you can choose from drop down menu...
    The big problem is:
    Local time is working...which is ok but "The Count Down" doesn't want to work and I don't have an idea why...
    here is the code...
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <HTML>
    <HEAD>
    PRIRANHA BROS RACING TEAM<BR>
    
    <table width="736" height="188" border="2">
      <tr>
        <td>
    <SCRIPT language=JavaScript>
    dateFuture = new Date(2007,05,10,19,00,00);
    
    function GetCount(){
    
    	dateNow = new Date();									//grab current date
    	amount = dateFuture.getTime() - dateNow.getTime();		//calc milliseconds between dates
    	delete dateNow;
    
    	// time is already past
    	if(amount < 0){
    		document.getElementById('countbox').innerHTML="Now!";
    	}
    	// date is still good
    	else{
    		days=0;hours=0;minns=0;seccs=0;out="";
    
    		amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs
    
    		days=Math.floor(amount/86400);//days
    		amount=amount%86400;
    
    		hours=Math.floor(amount/3600);//hours
    		amount=amount%3600;
    
    		minns=Math.floor(amount/60);//minutes
    		amount=amount%60;
    
    		seccs=Math.floor(amount);//seconds
    
    		if(days != 0){out += days +" day"+((days!=1)?"s":"")+", ";}
    		if(days != 0 || hours != 0){out += hours +" hour"+((hours!=1)?"s":"")+", ";}
    		if(days != 0 || hours != 0 || minns != 0){out += minns +" minute"+((minns!=1)?"s":"")+", ";}
    		out += seccs +" seconds";
    		document.getElementById('countbox').innerHTML=out;
    
    		setTimeout("GetCount()", 1000);
    	}
    }
    
    window.onload=function(){GetCount();} //call when everything has loaded
    
    
    </SCRIPT>
    <br>
    <DIV id=countbox></DIV>
        <b>Until the Big Race in Spain - Barcelona</b></td>
      </tr>
    </table>
    </HEAD>
    <BODY>
    <!--
    ////////////////////////////////////////////// 
    local time
    //////////////////////////////////////////////
    -->
    <table width="738" height="186" border="1">
      <tr>
        <td>
        <TABLE cellSpacing=0 cellPadding=3 width=100 border=0>
      <FORM name=where>
      <TBODY>
      <TR>
        <TD width="100%"><SELECT onchange=updateclock(this); size=1 name=city> 
            <OPTION value="" selected>Local time</OPTION> <OPTION value=10>Australia 
            - Melbourne [March 18]</OPTION> <OPTION value=8>Malaysia - Sepang [April 
            8]</OPTION> <OPTION value=3>Bahrain - Sakhir [April 15]</OPTION> <OPTION 
            value=2>Spain - Barcelona [May 13]</OPTION> <OPTION value=2>Monaco - 
            Monte Carlo [May 27]</OPTION> <OPTION value=-4>Canada - Montreal [June 
            10]</OPTION> <OPTION value=-4>USA - Indianapolis [June 17]</OPTION> 
            <OPTION value=2>France - Magny-Cours [July 1]</OPTION> <OPTION 
            value=1>UK - Silverstone [July 8]</OPTION> <OPTION value=2>Germany - 
            Nurgburgring [July 22]</OPTION> <OPTION value=2>Hungary - Hungaroring 
            [August 5]</OPTION> <OPTION value=3>Turkey - Istanbul park [August 
            26]</OPTION> <OPTION value=2>Italy - Monza [September 9]</OPTION> 
            <OPTION value=2>Belgium - Spa-Francorchamps [September 16]</OPTION> 
            <OPTION value=9>Japan - Fuji [September 30]</OPTION> <OPTION 
            value=8>China - Shanghai [October 7]</OPTION> <OPTION value=-3>Brazil - 
            Sao Paulo [October 21]</OPTION></SELECT> </TD></TR>
      <TR>
        <TD width="100%">
          
    <SCRIPT language=JavaScript>
    
    if (document.all||document.getElementById)
    document.write('<span id="worldclock" style="font:bold 16px Arial;"></span><br>')
    
    zone=0;
    isitlocal=true;
    ampm='';
    
    function updateclock(z){
    zone=z.options[z.selectedIndex].value;
    isitlocal=(z.options[0].selected)?true:false;
    }
    
    function WorldClock(){
    now=new Date();
    ofst=now.getTimezoneOffset()/60;
    secs=now.getSeconds();
    sec=-1.57+Math.PI*secs/30;
    mins=now.getMinutes();
    min=-1.57+Math.PI*mins/30;
    hr=(isitlocal)?now.getHours():(now.getHours() + parseInt(ofst)) + parseInt(zone);
    hrs=-1.575+Math.PI*hr/6+Math.PI*parseInt(now.getMinutes())/360;
    if (hr < 0) hr+=24;
    if (hr > 23) hr-=24;
    ampm = (hr > 11)?"PM":"AM";
    statusampm = ampm.toLowerCase();
    
    hr2 = hr;
    if (hr2 == 0) hr2=12;
    (hr2 < 13)?hr2:hr2 %= 12;
    if (hr2<10) hr2="0"+hr2
    
    var finaltime=hr2+':'+((mins < 10)?"0"+mins:mins)+':'+((secs < 10)?"0"+secs:secs)+' '+statusampm;
    
    if (document.all)
    worldclock.innerHTML=finaltime
    else if (document.getElementById)
    document.getElementById("worldclock").innerHTML=finaltime
    else if (document.layers){
    document.worldclockns.document.worldclockns2.document.write(finaltime)
    document.worldclockns.document.worldclockns2.document.close()
    }
    
    
    setTimeout('WorldClock()',1000);
    }
    
    window.onload=WorldClock
    
    </SCRIPT>
      </TR></TBODY></FORM></TABLE>
    
        </td>
      </tr>
    </table>
    <br>
    <BR>
    
    
    </BODY>
    </HTML>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,151
    Thanks
    203
    Thanked 2,548 Times in 2,526 Posts
    window.onload=WorldClock();

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by Philip M View Post
    window.onload=WorldClock();
    That's not right. That will set the return value of the WorldClock() function to window.onload. What you want is to assign the onload handler to the function which is what the poster has done.

    The problem here is there's onload conflict.
    Code:
    window.onload=function(){GetCount();} //call when everything has loaded
    ...
    window.onload=WorldClock
    You need to combine them into one onload.
    Code:
    window.onload = function(){
       GetCount();
       WorldClock();
    }
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    New Coder
    Join Date
    Jun 2005
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Thank you Glenn, it is working


  •  

    Posting Permissions

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