...

View Full Version : Countdown help please



mulan
12-21-2005, 10:42 PM
hello guys,

need help with my javascript code, basically i am trying to show countdown timer... this is my code and it works fine when page is loaded but the time is not ticking and it gives javascript error("Object required, line1, char1)...


<html>
<head>
<title>WebForm4</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
<script language="JavaScript" type="text/javascript">

function countdown_clock(year, month, day, hour, minute, format)
{
html_code = '<div id="countdown"></div>';
document.write(html_code);
countdown(year, month, day, hour, minute, format);
}

function countdown(year, month, day, hour, minute, format)
{
Today = new Date();
Todays_Year = Today.getFullYear() - 2000;
Todays_Month = Today.getMonth() + 1;

//Convert both today's date and the target date into miliseconds.
Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(),
Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();
Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();
//Find their difference, and convert that into seconds.
Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
if(Time_Left < 0)
Time_Left = 0;


//More datailed.
days = Math.floor(Time_Left / (60 * 60 * 24));
Time_Left %= (60 * 60 * 24);

hours = Math.floor(Time_Left / (60 * 60));
Time_Left %= (60 * 60);
minutes = Math.floor(Time_Left / 60);
Time_Left %= 60;
seconds = Time_Left;


var stext = days + ' days' + ' ';
stext += hours + ' hours' + ' ';
stext += minutes + ' minutes' + ' and ';
stext += seconds + ' seconds' ;

document.write(stext);
//Recursive call, keeps the clock ticking.
setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
}

</script>
<script type="text/javascript">countdown_clock(05, 12, 25, 00, 00, 1);</script>
</head>
<body MS_POSITIONING="GridLayout">

<form id="form1" name="form1" method="post" runat="server">
<div id="countdown"></div>
<span id="s1">Hello</span>

</form>

</body>
</html>

Thanks
newbeeee

Ranger56
12-21-2005, 10:59 PM
http://stuff.spiderseatbabies.com/countdown.html

view the source of that page, it's pretty easy to change

mulan
12-23-2005, 12:52 AM
can u please guide me how to write javascript for countdown between two times....like example
servertime : 12:00AM
Clienttime: 2:00AM
Countdown should start 2hr 00min 00sec
1hr 59min 01sec
1hr 59min 02sec
1hr 59min 03sec.....................
00hr 00min 02sec...............

Thanks

Ranger56
12-23-2005, 12:57 AM
nope.

Ancora
12-23-2005, 01:13 PM
<html>
<head>
<script type="text/javascript">

var refDate = new Date('2006 April 1 12:00')
var GMToffset = -5;

function update(){

var nForm = document.forms.countDown;
var currDate = new Date();
currDate.setHours(GMToffset+currDate.getHours()+currDate.getTimezoneOffset()/60);
var remTime = refDate-currDate;
var nDays = parseInt(remTime/86400000);
var nHours = parseInt((remTime-(nDays*86400000))/3600000);
var nMin = parseInt((remTime-(nDays*86400000)-(nHours*3600000))/60000);
var nSec = 60-(currDate.getSeconds());
var nYears = parseInt(nDays/365);
var nMonths = parseInt((nDays-(nYears*365))/30);
var rDays = parseInt((nDays-(nYears*365)-(nMonths*30)));
if (nYears < 10){nYears = "0"+nYears}
if (nMonths < 10){nMonths = "0"+nMonths}
if (rDays < 10){rDays = "0"+rDays}
if (nHours < 10){nHours = "0"+nHours}
if (nMin < 10){nMin = "0"+nMin}
if (nSec < 10){nSec = "0"+nSec}
if (nSec == 60){nSec = "00"}
nForm.years.value = nYears;
nForm.months.value = nMonths;
nForm.days.value = rDays;
nForm.hours.value = nHours;
nForm.minutes.value = nMin;
nForm.seconds.value = nSec;
setTimeout("update()",1000);
}

window.onload=update;

</script>
</head>
<body>
<form name='countDown'>
<p style='font-size:14pt'>Countdown To April 1, 2006, at 12:00:00 GMT-5:</p>
Years: <input type='text' name='years' size='5' readonly>
Months: <input type='text' name='months' size='5' readonly>
Days: <input type='text' name='days' size='5' readonly>
Hours: <input type='text' name='hours' size='5' readonly>
Minutes: <input type='text' name="minutes" size='5' readonly>
Seconds: <input type='text' name="seconds" size='5' readonly>
</form>
</body>
</html>

vwphillips
12-23-2005, 01:36 PM
diabolical comes to mind


<html>
<head>
<title>WebForm4</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
<script language="JavaScript" type="text/javascript">


function countdown(year, month, day, hour, minute, format)
{
Today = new Date();
Todays_Year = Today.getFullYear() - 2000;
Todays_Month = Today.getMonth() + 1;

//Convert both today's date and the target date into miliseconds.
Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(),Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();
Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();
//Find their difference, and convert that into seconds.
Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
if(Time_Left < 0)
Time_Left = 0;


//More datailed.
days = Math.floor(Time_Left / (60 * 60 * 24));
Time_Left %= (60 * 60 * 24);

hours = Math.floor(Time_Left / (60 * 60));
Time_Left %= (60 * 60);
minutes = Math.floor(Time_Left / 60);
Time_Left %= 60;
seconds = Time_Left;


var stext = days + ' days' + ' ';
stext += hours + ' hours' + ' ';
stext += minutes + ' minutes' + ' and ';
stext += seconds + ' seconds' ;
document.getElementById('CountDownDiv').innerHTML=stext;
//Recursive call, keeps the clock ticking.
setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
}

</script>
</head>
<body MS_POSITIONING="GridLayout" onload="countdown(05, 12, 25, 00, 00, 1);" >

<form id="form1" name="form1" method="post" runat="server">
<div id="CountDownDiv" ></div>
<span id="s1">Hello</span>

</form>

</body>
</html>


did not see previous posts but will leave my mods



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum