...

View Full Version : countdown timer



itsonlybarney
10-24-2005, 01:51 PM
hi guys,

i know you'll prob tell me to google or some other thing but i want to know how to have my javascript countdown in real time.....



<script>
<!--
/*
iTsOnLyBaRnEy's Countdown Timer
http://itsonlybarney.x10hosting.com/
itsonlybarney [at] gmail [dot] com
*/
var months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
function countdown(yr,m,d) {
var today = new Date();
year = yr;
month = m;
day = d;
var now_year = today.getYear();
var now_month = today.getMonth();
var now_day = today.getDate();
var now_hour = today.getHours();
var now_min = today.getMinutes();
var now_sec = today.getSeconds();

var now = months[now_month]+ " " +now_day+ ", " +now_year+ " " +now_hour+ ":" +now_min+ ":" +now_sec ;
var then = months[m-1]+ " " +d+ ", " +yr ;

difference = Date.parse(then) - Date.parse(now);

diff_day = Math.floor(difference/(60*60*1000*24)*1);
diff_hour = Math.floor((difference%(60*60*1000*24))/(60*60*1000)*1);
diff_min = Math.floor(((difference%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
diff_sec = Math.floor((((difference%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);

document.write("Only "+diff_day+ " days, " +diff_hour+ " hours, " +diff_min+ " minutes, and " +diff_sec+ " seconds until Christmas!");
setTimeout("countdown(year,month,day)",1000)
}

countdown(2005,12,25);
-->
</script>


but the seconds stay a constant until i refresh the page....is there a way to do it without refreshing the page....

i think i saw it done with a textbox but i don't really want to put a text box on my page....

Lerura
10-24-2005, 06:04 PM
try this:
<script>
<!--
/*
iTsOnLyBaRnEy's Countdown Timer
http://itsonlybarney.x10hosting.com/
itsonlybarney [at] gmail [dot] com
*/
var months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
function countdown(yr,m,d) {
var today = new Date();
year = yr;
if (!document.all){
year=year%1900
}
month = m;
day = d;
var now_weekday = today.getDay();
var now_year = today.getYear();
var now_month = today.getMonth();
var now_day = today.getDate();
var now_hour = today.getHours();
var now_min = today.getMinutes();
var now_sec = today.getSeconds();

var now = months[now_month]+ " " +now_day+ " " +now_year+ " " +now_hour+ ":" +now_min+ ":" +now_sec ;
var then = months[m-1]+ " " +d+ ", " +year+" 18:00:00";

difference = Date.parse(then) - Date.parse(now);

diff_day = Math.floor(difference/(60*60*1000*24)*1);
diff_hour = Math.floor((difference%(60*60*1000*24))/(60*60*1000)*1);
diff_min = Math.floor(((difference%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
diff_sec = Math.floor((((difference%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);

document.getElementById('ShowTime').innerHTML="Only "+diff_day+ " days, " +diff_hour+ " hours, " +diff_min+ " minutes, and " +diff_sec+ " seconds until Christmas!";
setTimeout("countdown(year,month,day)",1000)
}


// -->
</script>
<body onload="countdown(2005,12,26);">

<span style="width:420px" id="ShowTime">Christmas Countdown</span>

itsonlybarney
10-25-2005, 02:40 AM
thank you very much....



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum