Hi guys I have a countdown timer that is meant to run on a website. Unfortunately it isn't supported in Firefox, though it runs fine in Chrome and Opera (other browsers yet to be checked).
The theory behind it is that a time stamp, "END", is set on a page and the saved in a DB (all working fine). END is then retrieved (PHP) and fed into a jQuery function which counts down from the current time to END.
the php is all working as it should so my jQuery function is shown below as I'm sure it is located in here somewhere.
Thanks in advance guys!
// Code for a countdown timer
var countdown = function(end, elements){
var _second = 1000,
_minute = _second*60,
_hour = _minute*60,
_day = _hour*24,
finish = new Date(end),
timer,
calculate = function(){
var now = new Date(),
remaining = finish.getTime() - now.getTime(),
data;
if (isNaN(finish)){
console.log("Invalid date/time");
return;
};
if (remaining <= 0){
clearInterval(timer);
if (typeof callback ==='function'){
callback();
}
} else {
if (!timer){
timer = setInterval(calculate, _second);
};
data = {
"days" : Math.floor(remaining/_day),
"hours" : Math.floor((remaining % _day) / _hour),
"minutes" : Math.floor((remaining % _hour) / _minute),
"seconds" : Math.floor((remaining % _minute) / _second)
};
if (elements.length){
for (x in elements){
var x = elements[x];
data[x] = ('00' + data[x]).slice(-2);
document.getElementById(x).innerHTML = data[x];
};
};
};
};
calculate();
}
sorry, it is then called as follows:
<script>
var callback = function(){console.log('Done!')};
countdown("<?php get_deadline($conn);?>", ['days', 'hours', 'minutes', 'seconds'], callback); // Get deadline for exam name
</script>
As I say the php function is working fine!