Domanda

Newbie question: how do I pass numberWithCommas to my values such that my numbers are properly formatted? The code has just gotten too complex for me. It's working and I just need to format the number. Thanks!

<script type="text/javascript">

function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

if(!localStorage.Val1){
    localStorage.Val1 = 1412015;
    localStorage.Val2 = 20000;
    localStorage.Val3 = 20000;
}

    setInterval( function() {
    var popcounter = document.getElementById('pop');
    var ethanolcounter = document.getElementById('ethanol');
    var meatlcounter = document.getElementById('meat');


localStorage.Val1 = parseInt(localStorage.Val1,10)+1;
      localStorage.Val2 = parseInt(localStorage.Val2,10)+1000;
      localStorage.Val3 = parseInt(localStorage.Val3,10)+1000;

      popcounter.innerHTML = localStorage.Val1,10;
      ethanolcounter.innerHTML = localStorage.Val2;
      meatlcounter.innerHTML = localStorage.Val3;

    },1000);

</script>
È stato utile?

Soluzione

You're asking how to call a JavaScript function? Well, assuming your function works correctly:

popcounter.innerHTML=numberWithCommas(localStorage.Val1)
//repeat for Val2 and Val3
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top