I have designed 2 pages
For some unknown reason the second one is not refreshing the countdown script, it is only loading it once.
I have tried putting the javascript in various locations on the code and even calling it from an external file, however this just breaks the countdown script entirely.
For anyone who would like to use this countdown javascript please feel free to do so. The code is below:
<script>
var timeout;
// Uncomment below to use one.
var reset = function() {
//timeout = weekly(4, 12, 5); // 0=sunday, 6 = saturday
//timeout = daily(2, 0, 0);
timeout = new Date('25-Feb-2013');
}
var displayEndText = function() {
end_day = timeout.getDay();
end_date = timeout.getDate();
end_month = timeout.getMonth();
end_year = timeout.getFullYear();
end_hour = timeout.getHours();
var now = new Date();
todays_midnight = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
tomorrows_midnight = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 2);
dayText = "eek";
timeText = "bar";
a_p = "";
if (end_hour < 12) {
a_p = "AM";
} else {
a_p = "PM";
end_hour -= 12;
}
end_min = timeout.getMinutes();
if (end_min < 10) end_min = "0" + end_min;
if ((end_hour == 0) && (end_min == 0)) {
if (a_p == "AM") {
timeText = "Midnight";
var prevDay = new Date(timeout.getFullYear(), timeout.getMonth(), timeout.getDate() - 1);
end_day = prevDay.getDay();
end_date = prevDay.getDate();
} else {
timeText = "Midday";
}
} else {
timeText = end_hour + ":" + end_min +" " + a_p;
}
if (timeout <= todays_midnight) {
if ((end_hour == 0) && (end_min == 0)) {
dayText = "";
} else {
dayText = "Today";
}
} else if (timeout <= tomorrows_midnight) {
dayText = "Tomorrow";
} else {
d_names = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var sup;
switch (end_date) {
case 1:
case 21:
case 31:
sup = "st";
break;
case 2:
case 22:
sup = "nd";
break;
case 3:
case 23:
sup = "rd";
break;
default:
sup = "th";
}
dayText = d_names[end_day] + " " + end_date + "<SUP>" + sup + "</SUP> "
}
//document.getElementById('ed').innerHTML = d_names[end_day] + " " + end_date + "<SUP>" + sup + "</SUP> " + m_names[end_month] + " " + end_year + " at " + end_hour + " : " + end_min + " " + a_p;
document.getElementById('ed').innerHTML = dayText + " at " + timeText;
}
var display = function () {
var now = new Date();
var secondsToGo = Math.ceil((timeout - now) / 1000);
if (secondsToGo < 0) {
reset();
secondsToGo = Math.ceil((timeout - now) / 1000);
window.location = "http://modeliving.co.uk/index1.php";
}
var secs = Math.floor(secondsToGo % 60);
var minutesToGo = Math.floor(secondsToGo / 60);
var mins = Math.floor(minutesToGo % 60);
var hoursToGo = Math.floor(minutesToGo / 60);
var hours = hoursToGo % 24;
var daysToGo = Math.floor(hoursToGo / 24);
if (secs < 10) secs = "0" + secs;
if (mins < 10) mins = "0" + mins;
if (hours < 10) hours = "0" + hours;
document.getElementById('cdDays').innerHTML = daysToGo;
document.getElementById('cdHours').innerHTML = hours;
document.getElementById('cdMins').innerHTML = mins;
document.getElementById('cdSecs').innerHTML = secs;
// document.getElementById('cdAll').innerHTML = daysToGo + ' days ' + hours + ' hours ' + mins + ' minutes ' + secs + ' seconds';
displayEndText();
}
var weekly = function(dow, hour, min) {
if (typeof(dow)==='undefined') dow = 1; // sunday midnight
if (typeof(hour)==='undefined') hour = 0;
if (typeof(min)==='undefined') min = 0;
//dow = dow % 7;
var now = new Date();
var daysToGo = dow - now.getDay();
if (daysToGo < 0) daysToGo += 7;
if ((daysToGo == 0) && ((now.getHours()*60 + now.getMinutes()) >= (hour*60 + min))) daysToGo = 7;
var result = new Date(now.getFullYear(), now.getMonth(), now.getDate()+daysToGo, hour, min, 0, 0);
return result;
}
var daily = function(every, hour, min) {
if (typeof(every)==='undefined') every = 2; // every 2 days
if (typeof(hour)==='undefined') hour = 0;
if (typeof(min)==='undefined') min = 0;
var now = new Date();
var daysToGo = Math.floor(((now - 0) / 1000 / 60 / 60 / 24) % every);
if ((daysToGo == 0) && ((now.getHours()*60 + now.getMinutes()) >= (hour*60 + min))) daysToGo = every;
var result = new Date(now.getFullYear(), now.getMonth(), now.getDate()+daysToGo, hour, min, 0, 0);
return result;
}
reset();
display();
setInterval(display, 1000);
</script>
and then add this to the html:
<div id="cdDays"></div>
<div id="cdHours"></div>
<div id="cdMins"></div>
<div id="cdSecs"></div>
Comment line 178 and it works. You are trying to access an element with id=’ed’ that doesn’t exist.