title: how to add comma in textfield in html web page
body: <p>I have a web page in which I input data into an <code>&lt;input /&gt;</code>, like 1000 so I want it to look like 1,000 but it does not change the ID value it just show for only becuase I am using same the ID in other calculation so if 1,000 then it will show NaN... how can I avoid this?</p>
  
  <pre><code>&lt;input type="text" id="test" onBlur="addCommas()"&gt;
  &lt;script&gt;
      function addCommas(nStr){
          var offset = nStr.length % 3;
          if (offset == 0)
              return nStr.substring(0, offset) + nStr.substring(offset).replace(/([0-9]{3})(?=[0-9]+)/g, "$1,");
          else
              return nStr.substring(0, offset) + nStr.substring(offset).replace(/([0-9]{3})/g,    ",$1");
      }
      alert(addCommas("1234567"));
  &lt;/script&gt;
  </code></pre>
  
  <p>I have got this code from a forum... does anyone have an idea how to make this function simple so that it just shows in input box but when I get the ID value it shows 1000?</p>