Hi,
I am facing problems while trying to run a particular function at a specified time. I have a simple countdown script which is working fine. Now I want this to be scheduled to run at a future date and time.

I am enclosing the script below:


<html>
<head>
<script>
function countdown_clock(fromYear, fromMonth, fromDay, fromHour, fromMinute, fromSecond, toYear, toMonth, toDay, toHour, toMinute, toSecond){

var currentDate = new Date();
var fromDate = new Date(fromYear, fromMonth-1, fromDay, fromHour, fromMinute, fromSecond);

var strCalltoTemp = 'temp(' + currentDate + ',' + fromDate + ')';

t = setInterval( strCalltoTemp, 1000);

}

function temp(currentDate,fromDate){

if(currentDate.toString() == fromDate.toString()){
html_code = '<div id="countdown"></div>';
document.write(html_code);
countdown(fromYear, fromMonth, fromDay, fromHour, fromMinute, fromSecond, toYear, toMonth, toDay, toHour, toMinute, toSecond);

}

}

function countdown(fromYear, fromMonth, fromDay, fromHour, fromMinute, fromSecond, toYear, toMonth, toDay, toHour, toMinute, toSecond){

var dateFrom = new Date(fromYear, fromMonth - 1, fromDay, fromHour, fromMinute, fromSecond);
var dateTo = new Date(toYear, toMonth - 1, toDay, toHour, toMinute, toSecond);

//Find their difference, and convert that into seconds.
var timeLeft = Math.round((dateTo.getTime() - dateFrom.getTime()) / 1000);

if(timeLeft < 0){
timeLeft = 0;
}

decrementCountdown(timeLeft);
}

function decrementCountdown(timeLeft){

//temp
var tempTimeLeft = timeLeft;

var days = Math.floor(timeLeft / (60 * 60 * 24));
timeLeft %= (60 * 60 * 24);

var hours = Math.floor(timeLeft / (60 * 60));
timeLeft %= (60 * 60);

var minutes = Math.floor(timeLeft / 60);
timeLeft %= 60;

var seconds = timeLeft;

var dps = 's';
var hps = 's';
var mps = 's';
var sps = 's';

//ps is short for plural suffix.
if(days == 1){
dps ='';
}

if(hours == 1){
hps ='';
}

if(minutes == 1){
mps ='';
}

if(seconds == 1){
sps ='';
}

document.all.countdown.innerHTML = days + ' day' + dps + ' ';
document.all.countdown.innerHTML += hours + ' hour' + hps + ' ';
document.all.countdown.innerHTML += minutes + ' minute' + mps + ' and ';
document.all.countdown.innerHTML += seconds + ' second' + sps;


//Recursive call, keeps the clock ticking.
tempTimeLeft--;

if(tempTimeLeft != 0){
var strTemp = 'decrementCountdown(' + tempTimeLeft + ')';
setTimeout(strTemp, 1000);
}
}

</script>
</head>
<body>

<script>

countdown_clock(2008,10,29,14,0,0,2008,10,29,15,0,0);
</script>

</body>
</html>


The timer code in decrementCountdown is working fine. Now I need to run this at a date specified in fromDate. I tried various things, but I am not able to figure it out.

Please let me know if you need more details.

Any help will be greatly appreciated.

Regards
Anurag