title: JS: Add comma to a string
body: <p>I'm trying to add comma to a string and show that into label through following function :</p>
  
  <p><strong>HTML :</strong></p>
  
  <pre><code>&lt;input type="text" onkeyup="addCommas(this.value);" /&gt; &lt;br /&gt;&lt;br /&gt;
  &lt;label id="result"&gt;Result: &lt;/label&gt;
  </code></pre>
  
  <p><strong>JS</strong></p>
  
  <pre><code>function addCommas(nStr)
  {
      nStr += '';
      x = nStr.split('.');
      x1 = x[0];
      x2 = x.length &gt; 1 ? '.' + x[1] : '';
      var rgx = /(\d+)(\d{3})/;
      while (rgx.test(x1)) {
          x1 = x1.replace(rgx, '$1' + ',' + '$2');
      }
      var result = x1 + x2;
      document.getElementById('result').value = result;
  }
  </code></pre>
  
  <p><a href="http://jsfiddle.net/J4mLD/" rel="nofollow">JsFiddle</a></p>
  
  <p>But won't show the result into label.</p>
  
  <p>What am i doing wrong?</p>