0

I have a counter that adds 6 dollars to our total number every second, it counts up from a specific date and time so that it continues adding on to the total amount despite the page reloading.

<span id="counter-value"></span>


var amount = document.getElementById('counter-value');
var start = new Date("November 24, 2012 00:00:00").getTime();
var current;
update();

function update() {
    var current = (new Date().getTime() - start)/1000*6+138276343;//Starting total and number to increment total
    amount.innerText = formatMoney(current);
}

setInterval(update,1000);

function formatMoney(amount) {
    var dollars = Math.floor(amount).toString().split('');
    var cents = (Math.round((amount%1)*100)/100).toString().split('.')[1];
    if(typeof cents == 'undefined'){
        cents = '00';
    }else if(cents.length == 1){
        cents = cents + '0';
    }
    var str = '';
    for(i=dollars.length-1; i>=0; i--){
        str += dollars.splice(0,1);
        if(i%3 == 0 && i != 0) str += ',';
    }
    return '$' + str + '.' + cents;
    }
</script>

As stated in the question, this works in all of the other major browsers (that I want to test for at least) except for Firefox 31.1.1. Is there something in my code that is making this break?

Here is a JSfiddle for you to observe the behavior. Remember to view the fiddle in Firefox. This fiddle is not mine, but is identical to mine, save the hardcoded values.

ExcellentSP
  • 1,529
  • 4
  • 15
  • 39

1 Answers1

2

You need to replace innerText with innerHTML

http://jsfiddle.net/dm6LL/167/

function update() {
    var current = (new Date().getTime() - start)/1000*0.158+138276343;
    amount.innerHTML = formatMoney(current);
}
Huangism
  • 16,278
  • 7
  • 48
  • 74