title: Removing commas in 'live' input fields in jquery
body: <p>I have a series of input boxes in a table with some number of dynamically generated rows as such:</p>
  
  <pre><code>&lt;table id="someDataTable"&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td &gt;Some Title&lt;/td&gt;
              &lt;td &gt;Units&lt;/td&gt;
              &lt;td &gt;Val/Unit&lt;/td&gt;
              &lt;td &gt;Value&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;input type="text" size="30" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" size="14" class="units commas"/&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" size="14" class="value commas"/&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" size="14" readonly="readonly" class="autoTotal"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
  ...
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Now, I have a blur() call to add commas every time an input box is exited to add commas with the nifty <a href="https://code.google.com/p/jquery-numberformatter/" rel="nofollow">Number Formatter</a> plugin, and it simply does this:</p>
  
  <pre><code>&lt;script&gt;
  $(".commas").blur(function () {
       $(this).parseNumber({ format: "#,###", locale: "us" });
       $(this).formatNumber({ format: "#,###", locale: "us" });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>And it works beautifully.  Now, on the other side, I also have a chunk of code that does the form math automatically on every keystroke.  It has a call in initialize() that looks like this:</p>
  
  <pre><code> $(document).on('keyup', '#someDataTable', DoCalculations);
  </code></pre>
  
  <p>The function it invokes looks like this:</p>
  
  <pre><code>function DoCalculations() {
      $(this).find('tr').each(function () {
          var tUnits = $(this).find('.units').val();
          var tValue = $(this).find('.value').val();
          $(this).find('.autoTotal').val(Math.round(tUnits * tValue));
      });
  }
  </code></pre>
  
  <p>--</p>
  
  <p>Now, my problem:  I need to be able to rip out the commas to do the calculations.  I was hoping to be able to use NumberFormatter's parseNumber() function to do this, but it was having a small fit.  This was the alternate code in DoCalculations to attempt to accomplish that:</p>
  
  <pre><code>function DoCalculations() {
  
      $(this).find('tr').each(function () {
  
          var tTotal;
          var tUnits = $(this).find('.units').val();
          var tValue = $(this).find('.value').val();
  
          tUnits = $.parseNumber(tUnits, { format: "#,###", locale: "us" });
          tValue = $.parseNumber(tValue, { format: "#,###", locale: "us" });
  
          tTotal = tUnits * tValue;
          tTotal = $.formatNumber(tTotal, { format: "#,###", locale: "us" });
  
          $(this).find('.autoTotal').val(tTotal);
      });
  }
  </code></pre>
  
  <p>But it comes back with a runtime error in NumberFormatter.js, where it cannot get the property of numberString.indexOf of undefined or null reference.  Line 442 to be exact.  I'm not sure why though.  I originally thought it was because there were empty input boxes, but that turned out to not matter.</p>
  
  <p>At the end of the day, I need to strip out commas.</p>