title: JavaScript counter - immediately implement comma on page load
body: <p>I have a JavaScript counter (that works beautifully) and have now added commas, which works too.  The commas show up, BUT it only shows when the counter increments.  It's actually 4 counters and a total counter. 3 of the counters increment so often that it's not a problem, but I need the commas to show up on page load as there is a background and not just when the counter increments.  I think it has to do with where I call the addCommas(), but can't get it working when I call it differently.  I'll throw in some of the code:</p>
  <pre><code>var crate_msInterval = crate_interval * 1000;
  
  crate_count = parseInt((now - start_date)/crate_msInterval) * increment + start_value;
  
  document.getElementById('crate_counter').innerHTML = crate_count;
  setInterval(&quot;crate_count += increment; document.getElementById('crate_counter').innerHTML = addCommas(crate_count);&quot;, crate_msInterval);
  </code></pre>
  <p>And then the commas function I'm using:</p>
  <pre><code>function addCommas(str){
     var arr,int,dec;
     str += '';
  
     arr = str.split('.');
     int = arr[0] + '';
     dec = arr.length&gt;1?'.'+arr[1]:'';
  
     return int.replace(/(\d)(?=(\d{3})+$)/g,&quot;$1,&quot;) + dec;
  }
  </code></pre>
  <p>I hope I'm being clear enough. Any suggestions?</p>