JS Count Down Clock Help?!?

I am trying to install a weekly Countdown Clock on my index.php page. The problem is that when the computer clock hits 12am the clock resets back to 7 days and does not continue. it will count down for one day but that is all. The JS and PHP are in the head tag. Can you please review the code and let me know what need to change?

here is the site:

ecwvideos.com/index.php

[php][/php]

[php]// Andrew Urquhart : CountDown Timer : http://andrewu.co.uk/clj/countdown/
function CD_T(id,e){var n=new Date();CD_D(+n,id,e);setTimeout(“if(typeof CD_T==‘function’){CD_T(’”+id+"’,"+e+")}",1100-n.getMilliseconds())};function CD_D(n,id,e){var ms=e-n;if(ms<=0) ms*=-1;var d=Math.floor(ms/864E5);ms-=d864E5;var h=Math.floor(ms/36E5);ms-=h36E5;var m=Math.floor(ms/6E4);ms-=m6E4;var s=Math.floor(ms/1E3);if(CD_OBJS[id]){CD_OBJS[id].innerHTML=d+" day"+(d==1?" ":"s ")+CD_ZP(h)+"h "+CD_ZP(m)+"m “+CD_ZP(s)+“s”}};function CD_ZP(i){return(i<10?“0”+i:i)};function CD_Init(){var pref=“countdown”;var objH=1;if(document.getElementById||document.all){for(var i=1;objH;++i){var id=pref+i;objH=document.getElementById?document.getElementById(id):document.all[id];if(objH&&(typeof objH.innerHTML)!=‘undefined’){var s=objH.innerHTML;var dt=CD_Parse(s);if(!isNaN(dt)){CD_OBJS[id]=objH;CD_T(id,dt.valueOf());if(objH.style){objH.style.visibility=“visible”}}else {objH.innerHTML=s+”<a href=“http://andrewu.co.uk/clj/countdown/” title=“Countdown Error:Invalid date format used,check documentation (see link)”>"}}}}};function CD_Parse(strDate){var objReDte=/(\d{4})-(\d{1,2})-(\d{1,2})\s+(\d{1,2}):(\d{1,2}):(\d{0,2})\s+GMT([+-])(\d{1,2}):?(\d{1,2})?/;if(strDate.match(objReDte)){var d=new Date(0);d.setUTCFullYear(+RegExp.$1,+RegExp.$2-1,+RegExp.$3);d.setUTCHours(+RegExp.$4,+RegExp.$5,+RegExp.$6);var tzs=(RegExp.$7=="-"?-1:1);var tzh=+RegExp.$8;var tzm=+RegExp.$9;if(tzh){d.setUTCHours(d.getUTCHours()-tzhtzs)}if(tzm){d.setUTCMinutes(d.getUTCMinutes()-tzmtzs)};return d}else {return NaN}};var CD_OBJS=new Object();if(window.attachEvent){window.attachEvent(‘onload’,CD_Init)}else if(window.addEventListener){window.addEventListener(“load”,CD_Init,false)}else {window.onload=CD_Init};
[/php]

Thank you.

You can use good script from here : http://www.smashingapps.com/2012/12/04/16-cool-countdown-timer-scripts-for-your-projects.html

Ive seen those before but I’m trying to keep the look I have already. Does anyone see the problem in the code?

Well, the formatting was a mess on your code. I looked at both that you posted and both are missing one ending character. Just before the window.onload function, you do not use a ‘;’ to end the previous function. Therefore, the window.onload becomes part of the Getcount() function. Not sure if you wanted that or not.
(I do not have time to test after all the formatting…)
In the obfuscation code, which you should NEVER post on a help site, I reformatted it correctly to be able to see what it does and it is missing and ending bracket. “}” This is in the CD_Parse function. It does not look correct and this function may not work.

I have no idea if either of these is the cause of you code problem, but, either could cause it. Let us know if you figured it out. Here is a formatted copy of the obfuscated code:
[php]
// Andrew Urquhart : CountDown Timer : http://andrewu.co.uk/clj/countdown/

function CD_T(id,e) {
var n=new Date();
CD_D(+n,id,e);
setTimeout(“if(typeof CD_T==‘function’){CD_T(’” + id + “’,” + e + “)}”,1100-n.getMilliseconds())
};

function CD_D(n,id,e) {
var ms=e-n;
if(ms<=0) ms*=-1;
var d=Math.floor(ms/864E5);
ms-=d864E5;
var h=Math.floor(ms/36E5);
ms-=h
36E5;
var m=Math.floor(ms/6E4);
ms-=m*6E4;
var s=Math.floor(ms/1E3);
if(CD_OBJS[id]){
CD_OBJS[id].innerHTML=d + " day"+(d==1?" ":"s ") + CD_ZP(h)+"h " + CD_ZP(m) + "m " + CD_ZP(s) + “s”
}
};

function CD_ZP(i) {
return(i<10?“0”+i:i)
};

function CD_Init() {
var pref=“countdown”;
var objH=1;
if(document.getElementById||document.all) {
for(var i=1;objH;++i){
var id=pref+i;
objH=document.getElementById?document.getElementById(id):document.all[id];
if(objH&&(typeof objH.innerHTML)!=‘undefined’) {
var s=objH.innerHTML;
var dt=CD_Parse(s);
if(!isNaN(dt)) {
CD_OBJS[id]=objH;
CD_T(id,dt.valueOf());
if(objH.style) {
objH.style.visibility=“visible”
}
}else {
objH.innerHTML=s+"<a href=“http://andrewu.co.uk/clj/countdown/” title=“Countdown Error:Invalid date format used,check documentation (see link)”>*"
}
}
}
}
};

function CD_Parse(strDate) {
var objReDte=/(\d{4})-(\d{1,2})-(\d{1,2})\s+(\d{1,2}):(\d{1,2}):(\d{0,2})\s+GMT([±])(\d{1,2}):?(\d{1,2})?/;
if(strDate.match(objReDte)) {
var d=new Date(0);
d.setUTCFullYear(+RegExp.$1,+RegExp.$2-1,+RegExp.$3);
d.setUTCHours(+RegExp.$4,+RegExp.$5,+RegExp.$6);
var tzs=(RegExp.$7=="-"?-1:1);
var tzh=+RegExp.$8;var tzm=+RegExp.$9;
if(tzh){
d.setUTCHours(d.getUTCHours()-tzhtzs)
}
if(tzm){
d.setUTCMinutes(d.getUTCMinutes()-tzm
tzs)};
return d
} else {
return NaN
}
};
var CD_OBJS=new Object();
if(window.attachEvent){
window.attachEvent(‘onload’,CD_Init)
}else if(window.addEventListener) {
window.addEventListener(“load”,CD_Init,false)
}else { //NO END BRACKET FOR THIS ELSE and IF<<<<<<<<<<<<<<<<<----------------------------
window.onload=CD_Init
};

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service