sebi
sebi

Reputation: 47

Firefox shows [object HTMLDivElement] instead of value of JS calculation

The following script should calculate an amount of money which was saved. in every type of browser its working (IE,Chrome,Opera) but not FF. It shows me [object HTMLDivElement] instead of the value which was calculated.

  var betragsec = ({input:loszahlen}*.25)/31536000;
    var amount = document.getElementById("amount");
    var now = new Date();
    var start = new Date("Januar 01, 2015, 00:00:00");
    var diff = (now - start)/1000;
    var current =(diff*betragsec);
    update();
    function update() {
        amount.innerText = formatMoney(current);
    }
    setInterval(function(){
        current += betragsec;
        update();
        },1000);
    function formatMoney(amount) {
        var euros = 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=euros.length-1; i>=0; i--){
            str += euros.splice(0,1);
            if(i%3 == 0 && i != 0) str += '.';
        }
        return  str + ',' + cents + ' ' + '\u20AC';

Upvotes: 0

Views: 532

Answers (1)

ylerjen
ylerjen

Reputation: 4249

It's because FF use the .textContent property, which is W3C complient.

You can use textContent or innerHTML to get this code work cross browser

amount.textContent = formatMoney(current);
// OR
amount.innerHTML = formatMoney(current);

Duplicate of this question can be : 'innerText' works in IE, but not in Firefox

Upvotes: 1

Related Questions