Javascript problem

Associate
Joined
28 Dec 2002
Posts
2,400
Location
Northern Ireland
Guys im tring to create a countdown timer. The following is the code i have already placed in a .js file:

// JavaScript Document
<script language="JavaScript">
TargetDate = "12/31/2020 5:00 AM";
BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "It is finally here!";
</script>
<script language="JavaScript" src="http://www.clients.pcsupergeeks.co.uk/cccc/countdown.js"></script>
*/

function calcage(secs, num1, num2) {
s = ((Math.floor(secs/num1))%num2).toString();
if (LeadingZero && s.length < 2)
s = "0" + s;
return "<b>" + s + "</b>";
}

function CountBack(secs) {
if (secs < 0) {
document.getElementById("cntdwn").innerHTML = FinishMessage;
return;
}
DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));
DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));

document.getElementById("cntdwn").innerHTML = DisplayStr;
if (CountActive)
setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod);
}

function putspan(backcolor, forecolor) {
document.write("<span id='cntdwn' style='background-color:" + backcolor +
"; color:" + forecolor + "'></span>");
}

if (typeof(BackColor)=="undefined")
BackColor = "white";
if (typeof(ForeColor)=="undefined")
ForeColor= "black";
if (typeof(TargetDate)=="undefined")
TargetDate = "12/31/2020 5:00 AM";
if (typeof(DisplayFormat)=="undefined")
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
if (typeof(CountActive)=="undefined")
CountActive = true;
if (typeof(FinishMessage)=="undefined")
FinishMessage = "";
if (typeof(CountStepper)!="number")
CountStepper = -1;
if (typeof(LeadingZero)=="undefined")
LeadingZero = true;


CountStepper = Math.ceil(CountStepper);
if (CountStepper == 0)
CountActive = false;
var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
putspan(BackColor, ForeColor);
var dthen = new Date(TargetDate);
var dnow = new Date();
if(CountStepper>0)
ddiff = new Date(dnow-dthen);
else
ddiff = new Date(dthen-dnow);
gsecs = Math.floor(ddiff.valueOf()/1000);
CountBack(gsecs);

This is the code i have on the page where i want to place the countdown timer:

<body>
<script language="JavaScript">
TargetDate = "12/31/2020 5:00 AM";
BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "It is finally here!";
</script>
<script language="JavaScript" src="http://www.clients.pcsupergeeks.co.uk/cccc/countdown.js"></script>
</body>
</html>

Its not working at all? am i missing something here, all this code is copied from a site that allows it before anyone asks. The giuy who hosts it said to change the src to where i will have each file and that is exactly what i did but it doesnt work.

Also why you guys are here im looking to automatically load a page when the countdown timer finishes and this should be the page everyone sees after the countdown is finished.

any ideas
ace
 
You are missing a lot there.
For starters:
the js file shouldn't have
Code:
<script language="JavaScript">
TargetDate = "12/31/2020 5:00 AM";
BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "It is finally here!";
</script>
<script language="JavaScript" src="http://www.clients.pcsupergeeks.co.uk/cccc/countdown.js"></script>
*/
in it.

you need a cntdwn element in your html file

and this script only puts a message to the screen. It doesn't move to a different page. Although you could make it.


oh and http://www.clients.pcsupergeeks.co.uk/cccc/countdown.js doesn't exist. so you've not got that right either
 
You are missing a lot there.
For starters:
the js file shouldn't have
Code:
<script language="JavaScript">
TargetDate = "12/31/2020 5:00 AM";
BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "It is finally here!";
</script>
<script language="JavaScript" src="http://www.clients.pcsupergeeks.co.uk/cccc/countdown.js"></script>
*/
in it.

you need a cntdwn element in your html file

and this script only puts a message to the screen. It doesn't move to a different page. Although you could make it.


oh and http://www.clients.pcsupergeeks.co.uk/cccc/countdown.js doesn't exist. so you've not got that right either

Got i working guys thanks but how do i automatically get the page to change after the countdown has ended and also to allows go to that page after the countdown has ended????
 
Back
Top Bottom