We help IT Professionals succeed at work.

timer not working in FF

This is only showing maybe one div row in FF not sure why. But works ok in IE.

<!-- body tag -->
  <div id='Timer0' 
                            style="display:none;">
                            12/27/2011 12:00:00 AM</div>
                        <div id='Timer0d'></div>
                        
                         <div id='Timer1' 
                            style="display:none;">
                           12/22/2011 12:00:00 AM</div>
                        <div id='Timer1d'></div>

     <div id='Timer2' 
                            style="display:none;">
                           12/29/2011 12:00:00 AM</div>
                        <div id='Timer2d'></div>

<!-- end body -->
<!-- script -->
Count down timer. 


    var maxTimer = 2;  /* The MaxTimer must be the same amount of rows starting at 0 */
    var nullTimers = new Array();
    function GetTimeTest(millisec) {
        function D2(val) {
            return (val < 10) ? '0' + val : val
        }
        var sec = Math.floor(millisec / 1000)
        var days = Math.floor(sec / 86400)
        sec -= days * 86400
        var hours = Math.floor(sec / 3600)
        sec -= hours * 3600
        var minutes = Math.floor(sec / 60)
        sec -= minutes * 60
        if (isNaN(parseInt(days))) {
            return ('');
        }
        else {
            return days + ' days ' + D2(hours) + ':' + D2(minutes) + ':' + D2(sec)
        } 
    }
    function CountDown() {
        var now = new Date()
        for (var i = 0; i <= maxTimer; i++) {
            div = document.getElementById('Timer' + i)
            div2 = document.getElementById('Timer' + i + 'd')
            var endDate = new Date(div.innerHTML)
            if (endDate.getTime() - now.getTime() <= 0) {
                if (!nullTimers[i]) {
                    nullTimers[i] = 1;
                    div2.innerHTML = 'Product has expired'
                }
            } else {
                div2.innerHTML = GetTimeTest(endDate.getTime() - now.getTime())
                div2 = document.all.tags('blink');
            }
            div2.innerHTML
        }
    }
    for (i = 0; i <= maxTimer; i++) nullTimers[i] = 0;
    var TimerID = setInterval('CountDown()', 1000)

Open in new window

Comment
Watch Question

IT Expert
Top Expert 2009
Commented:
This is illegal script

                div2 = document.all.tags('blink'); // no .all in Fx and no tags called blink in the code

            div2.innerHTML <<<< you need to do something here

When I remove these two lines, I get 3 countdowns in Fx

http://jsfiddle.net/mplungjan/Lx6Da/
var maxTimer = 2;  /* The MaxTimer must be the same amount of rows starting at 0 */
    var nullTimers = new Array();
    function GetTimeTest(millisec) {
        function D2(val) {
            return (val < 10) ? '0' + val : val
        }
        var sec = Math.floor(millisec / 1000)
        var days = Math.floor(sec / 86400)
        sec -= days * 86400
        var hours = Math.floor(sec / 3600)
        sec -= hours * 3600
        var minutes = Math.floor(sec / 60)
        sec -= minutes * 60
        if (isNaN(parseInt(days))) {
            return ('');
        }
        else {
            return days + ' days ' + D2(hours) + ':' + D2(minutes) + ':' + D2(sec)
        }
    }
    function CountDown() {
        var now = new Date()
        for (var i = 0; i <= maxTimer; i++) {
            div = document.getElementById('Timer' + i)
            div2 = document.getElementById('Timer' + i + 'd')
            var endDate = new Date(div.innerHTML)
            if (endDate.getTime() - now.getTime() <= 0) {
                if (!nullTimers[i]) {
                    nullTimers[i] = 1;
                    div2.innerHTML = 'Product has expired'
                }
            } else {
                div2.innerHTML = GetTimeTest(endDate.getTime() - now.getTime())
            }
        }
    }
    for (i = 0; i <= maxTimer; i++) nullTimers[i] = 0;
    var TimerID = setInterval(CountDown, 1000)

Open in new window

Seven priceFull Stack

Author

Commented:
tks