title: Addition and subtraction multiple text fields
body: <p>I have a table in which I'm trying to add and subtract multiple text fields using jQuery on <code>keydown</code> or <code>blur</code>. While I can add successfully, I get all wrong results for subtraction. </p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;input type="text" class="add" /&gt;
  &lt;input type="text" class="add" /&gt;
  &lt;input type="text" class="sub" /&gt;
  &lt;input type="text" class="sub" /&gt;
  &lt;label id="total"&gt;&lt;/label&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code> $('.add').blur(function () {
       var sum = 0;
       $('.add').each(function () {
           if (!isNaN(this.value) &amp;&amp; this.value.length != 0) {
               sum += parseFloat(this.value);
           }
       });
  
       $('#total').text(sum.toFixed(2));
  
   });
  
   $('.sub').blur(function () {
       var sum = 0;
       var val = $('#total').text();
       $('.sub').each(function () {
           if (!isNaN(this.value) &amp;&amp; this.value.length != 0) {
               sum -= parseFloat(this.value);
  
           }
       });
       val = parseFloat(sum) - parseFloat(val);
       $('#total').text(val);
  
   });
  </code></pre>
  
  <p><a href="http://jsfiddle.net/QHgdZ/" rel="nofollow">FIDDLE</a></p>