title: Summing up input values
body: <p>I am trying to use jquery to iterate through all '.invoice-lines' and generate a total by summing up all values in the '.amount-input' div. </p>
  
  <p>AJAX dynamically generates the default values in '.amount-input' which can be manually changed by the user. I have been trying to create a function so that every time new data comes in using AJAX, a call will be made to the function updateTotal(), which iterates through all the non-empty 'amount-input' values and recalculates the total. I have been having a really tough time accomplishing this, and I would greatly appreciate any help.</p>
  
  <p>JQuery - This is my jquery so far (pseudo code)</p>
  
  <pre><code>function updateTotal(){
     var total=0;
      for(i=0; i &lt; $('.invoice-line').length; i++){
           if($('.amount-input').eq(i).val() != empty)){
                total += $('.amount-input').eq(i).val();
            }
      }
      $('.total').val("$" + total);
  }
  </code></pre>
  
  <p>Markup</p>
  
  <pre><code>&lt;?
      for(i=0; i &lt; 25; i++){
      echo'   &lt;div class="invoice-line"&gt;
                  &lt;div class="prod-id-cell"&gt;&lt;input type="text" class="prod-id-input"&gt;&lt;/div&gt;
  
                  &lt;div class="amount-cell"&gt;&lt;input class="amount-input" type="text" /&gt;&lt;/div&gt;
              &lt;/div&gt;';
      }
  ?&gt;
      &lt;div class="total"&gt;$0.00&lt;/div&gt;
  </code></pre>