mulan
12-21-2005, 09: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
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