All - Here is a very simple piece of javascript that will produce text to countdowm to your upcoming events. You may need change a few lines. like
dateFuture = new Date(2011,2,18,19,45,00) - this is the date of the event, the date listed here is March 18, 2001 @ 7:45PM
{document.getElementById('countbox').innerHTML="Play Ball!";}, and -this is what it will say when the time expires
document.getElementById('countbox').innerHTML=out+" until Opening Day!"; - the words after the plus sign
you can see it on my site athttp://baseball.iscorecentral.com/baltimoreblueclaws
copy the lines below and paste them into the your site at the correct location, you will not see the result until you logout and refresh your home page..............................
<div id="countbox" style="position: absolute; left: 400px;">
<script type="text/javascript">// <![CDATA[
dateFuture = new Date(2011,2,18,19,45,00)
function GetCount(){
dateNow = new Date();
amount = dateFuture.getTime() - dateNow.getTime();
delete dateNow;
if(amount < 0)
{document.getElementById('countbox').innerHTML="Play Ball!";}
else{
days=0;hours=0;mins=0;secs=0;out="";
amount = Math.floor(amount/1000);
days=Math.floor(amount/86400);
amount=amount%86400;
hours=Math.floor(amount/3600);
amount=amount%3600;
mins=Math.floor(amount/60);
amount=amount%60;
secs=Math.floor(amount);
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 || mins != 0){out += mins +" minute"+((mins!=1)?"s":"")+", ";}
out += secs +" seconds";
document.getElementById('countbox').innerHTML=out+" until Opening Day!";
setTimeout("GetCount()", 1000);
}
}
window.onload=GetCount;
// ]]></script>
</div>
Simple JavaScript Countdown Code
- BlueClawDad
- Posts: 42
- Joined: Fri Mar 04, 2011 8:48 am
Re: Simple JavaScript Countdown Code
Thank you for the contribution to the community!
