title: ajax delete mysql id dynamic calculateSum() not updating
body: <p>Hi I have a very large edit from that shows items coming from mysql database and the ability to add/delete new rows. I use jquery to calculate the prices, subtotal, tax and total. This all works as does the add new row and delete rows. 
  However, the items coming from the database that already exist I use ajax to delete items to refresh results without submitting the form. It works except it won't calculate the totals.
  The add new rows and then delete them that have no id in the database yet use jquery to delete and work as well as giving the correct calculation when deleted. The form is way too large so will only give the bits that need help.
  This is the ajax and jquery - the delete via ajax is what doesn't recalculate.
  `                $(document).on('click', '.delete-rows', function() {
                      var id = $(this).attr("id");</p>
  
  <pre><code>                if (confirm("Are you sure you want to delete this Item?")) {
                      $.ajax({
                          type: "POST",
                          url: "job_remove_material_new.php",
                          data: ({
                              id: id
                          }),
                          cache: false,
                          success: function(html) {
                              $(".delete_mem" + id).fadeOut('slow');
                              calculateSum();
                          }
                      });
                  } else {
                      return false;
                  }
  
              });
  
  
               $(document).ready(function () {  
  
                  // remove product row
                  $('#invoice_tables').on('click', ".delete-row", function(e){
                      e.preventDefault();
                      $(this).closest('.clone').remove();
                      calculateSum();
                  });
  
                  var cloned = $('#invoice_tables .clone').clone();
                  $(".add-row").click(function (e) {
                      e.preventDefault();
                      cloned.clone().appendTo('#invoice_tables'); 
                  });
  
                  calculateSum();
  
                  $('#invoice_tables').on('change keyup paste', '.prices', function() {
                      //updateTotals(this);
                      calculateSum();
                  });
  
               });
                $(document).ready(function() {
                  calculateSum();
                  $(".prices").keyup(calculateSum);
                  $("#tax").keyup(displayTax);
              });
  
              var sum; 
  
              function calculateSum() {
                  sum = 0;
                  //iterate through each textboxes and add the values
                  $(".prices").each(function() {
                      //add only if the value is number
                      if (!isNaN(this.value) &amp;&amp; this.value.length != 0) {
                          sum += parseFloat(this.value);
                      }
                  }); 
                  $("#subtotal").val(sum.toFixed(2));
  
                  displayTax();
              }
              function displayTax() { 
                  var taxFloat = parseFloat($('#tax').val());
                  if (isNaN(taxFloat))
                      taxFloat = 1.1;
  
                  var total = taxFloat * sum;
                  $("#total").val(total.toFixed(2)); 
  
                  var gst = total / 11;
                  $("#gst").val(gst.toFixed(2)); 
              }
  </code></pre>
  
  <p><code>
  This is the form corresponding to the above:
  </code>                echo ' </p>
  
  <pre><code>             &lt;div class="row clones delete_mem'.$material_id.'"&gt;
                &lt;div class="col-md-12"&gt;
                &lt;div class="input-group-btn"&gt; 
               &lt;a id="'.$material_id.'" class="btn btn-danger btn-xs delete-rows"&gt;&lt;span class="glyphicon glyphicon-remove" aria-hidden="true"&gt;&lt;/span&gt;&lt;/a&gt;
               &lt;/div&gt;&lt;/div&gt;
  
               &lt;div class="clear"&gt;&lt;/div&gt;
               &lt;div class="col-md-12"&gt;
               &lt;div class="col-md-9 col-sm-12 col-xs-12"&gt;
               &lt;label&gt;Description&lt;/label&gt;
                &lt;div class="form-group"&gt;
                &lt;input type="hidden" name="material_id[]" id="material_id[]" value="'.$material_id.'"&gt;
                 &lt;input type="hidden" name="job_id[]" id="job_id[]" value="'.$job_id.'"&gt;
  
  
                                              &lt;textarea class="form-control item-input invoice_product editors" id="job_mat_descs[]" name="job_mat_descs[]" placeholder="Enter item title and / or description" /&gt;'.$job_mat_descs.'&lt;/textarea&gt;
                &lt;/div&gt;
  
              &lt;/div&gt;
               &lt;div class="col-md-2 hidden"&gt;
               &lt;div class="form-group"&gt;&lt;label&gt;&lt;/label&gt;
                                              &lt;input hidden class="form-control" id="job_mat_qtys[]" name="job_mat_qtys[]" value="1"&gt;
                                          &lt;/div&gt;
                                          &lt;/div&gt;
  
              &lt;div class="col-md-3 col-sm-12 col-xs-12"&gt;&lt;label&gt;Price&lt;/label&gt;;
                &lt;div class="input-group input-group"&gt;
                                              &lt;span class="input-group-addon"&gt;'.CURRENCY.'&lt;/span&gt;
                                              &lt;input type="text" class="form-control prices" id="job_mat_costs[]" name="job_mat_costs[]" aria-describedby="sizing-addon1" placeholder="0.00" value="'.number_format($prices, 2).'"&gt;
                                          &lt;/div&gt;
  
  
              &lt;/div&gt;
              &lt;/div&gt;
               &lt;div class="clear"&gt;&lt;/div&gt;
               &lt;/div&gt;';
  </code></pre>
  
  <p>$itemsPrice += $prices;</p>
  
  <pre><code>            &lt;div class="row clone"&gt;
                                          &lt;div class="col-md-12"&gt;
                                            &lt;div class="input-group-btn"&gt; &lt;a href="#" class="btn btn-danger btn-xs delete-row"&gt;&lt;span class="glyphicon glyphicon-remove" aria-hidden="true"&gt;&lt;/span&gt;&lt;/a&gt; &lt;/div&gt;
                                          &lt;/div&gt;
                                          &lt;div class="clear"&gt;&lt;/div&gt;
                                          &lt;div class="col-md-12"&gt;
                                            &lt;div class="col-md-9 col-sm-12 col-xs-12"&gt;
                                              &lt;label&gt;Description&lt;/label&gt;
                                              &lt;div class="form-group"&gt;
                                                &lt;input type="hidden" name="job_id[]" id="job_id[]" value="&lt;?php echo $job_id; ?&gt;"&gt;
                                                &lt;textarea class="form-control editors" id="job_mat_desc[]" name="job_mat_desc[]" placeholder="Enter item title and / or description" /&gt;
                                                &lt;/textarea&gt;
                                                &lt;script&gt;
  
                      $( "body" ).on( "click", ".add-row", function() {
                       // $( '&lt;textarea name="job_mat_desc[]" class="form-control editors"&gt;&lt;/textarea&gt;' ).appendTo( "#job_mat_desc" );
                        $( 'textarea.editors' ).ckeditor();
                      });
  
                                              CKEDITOR.replace("editors[]" );&lt;/script&gt; 
                                              &lt;/div&gt;
                                            &lt;/div&gt;
                                            &lt;div class="col-md-2 hidden"&gt;
                                              &lt;div class="form-group"&gt;
                                                &lt;label&gt;&lt;/label&gt;
                                                &lt;input hidden class="form-control" id="job_mat_qty[]" name="job_mat_qty[]" value="1"&gt;
                                              &lt;/div&gt;
                                            &lt;/div&gt;
                                            &lt;div class="col-md-3 col-sm-12 col-xs-12"&gt;
                                              &lt;label&gt;Price&lt;/label&gt;
                                              ;
                                              &lt;div class="input-group input-group"&gt; &lt;span class="input-group-addon"&gt;&lt;?php echo CURRENCY; ?&gt;&lt;/span&gt;
                                                &lt;input type="text" class="form-control prices" id="job_mat_cost[]" name="job_mat_cost[]" aria-describedby="sizing-addon1" placeholder="0.00" value=""&gt;
                                              &lt;/div&gt;
                                            &lt;/div&gt;
                                            &lt;div class="clear"&gt;&lt;/div&gt;
                                          &lt;/div&gt;
                                        &lt;/div&gt;
                                      &lt;/div&gt;
                                      &lt;div class="clear"&gt;&lt;/div&gt;
                                      &lt;div class="row text-center text-green"&gt;
                                        &lt;div class="panel-footer"&gt;
                                          &lt;h2&gt;&lt;a href="#" class="btn btn-success btn-lg add-row"&gt;&lt;span class="glyphicon glyphicon-plus" aria-hidden="true"&gt;&lt;/span&gt; Add Item&lt;/a&gt; &lt;/h2&gt;
                                        &lt;/div&gt;
                                      &lt;/div&gt;
                                      &lt;div class="clear"&gt;&lt;/div&gt;
                                      &lt;div class="row m-t-lg m-b-lg"&gt;
                                        &lt;?php 
  
              $subtotal = $itemsPrice + $shipping; 
              $gst = ($subtotal * .10);
              $total = ($subtotal + $gst);
              ?&gt;
                                        &lt;div class="col-xs-12 col-sm-6 col-md-6 col-lg-6"&gt; &lt;/div&gt;
                                        &lt;div id="invoice_totals" class="col-xs-offset-1 col-xs-10 col-sm-offset-1 col-md-offset-3 col-lg-offset-3 col-sm-4 col-md-3 col-lg-3"&gt;
                                        &lt;label&gt;SHIPPING&lt;/label&gt;
                                        &lt;div class="input-group input-group"&gt; &lt;span class="input-group-addon"&gt;&lt;?php echo CURRENCY; ?&gt;&lt;/span&gt;&lt;input name="shipping" type="text" placeholder="0.00"  class="prices text-left form-control" id="shipping" aria-describedby="sizing-addon1"value="&lt;?php echo number_format($shipping, 2); ?&gt;" size="16"&gt;&lt;/div&gt;
               &lt;label&gt;SUBTOTAL&lt;/label&gt;
               &lt;div class="input-group input-group"&gt; &lt;span class="input-group-addon"&gt;&lt;?php echo CURRENCY; ?&gt;&lt;/span&gt; &lt;input name="subtotal" type="text"  class="txt1 disabled form-control" id="subtotal" value="&lt;?php echo number_format($subtotal, 2); ?&gt;" size="16" aria-describedby="sizing-addon1" placeholder="0.00" readonly="readonly"&gt;&lt;/div&gt;
              &lt;label&gt;GST&lt;/label&gt; &lt;div class="input-group input-group"&gt; &lt;span class="input-group-addon"&gt;&lt;?php echo CURRENCY; ?&gt;&lt;/span&gt;&lt;input name="gst" type="text" class="txt1 form-control disabled"  id="gst" value="&lt;?php echo number_format($gst, 2); ?&gt;" size="16" aria-describedby="sizing-addon1" placeholder="0.00" readonly="readonly"&gt;&lt;/div&gt;
  
              &lt;label&gt;TOTAL&lt;/label&gt; &lt;div class="input-group input-group"&gt; &lt;span class="input-group-addon"&gt;&lt;?php echo CURRENCY; ?&gt;&lt;/span&gt; &lt;input name="total" type="text"  class="txt2 form-control disabled" id="total" value="&lt;?php echo number_format($total, 2); ?&gt;" size="16" aria-describedby="sizing-addon1" placeholder="0.00" readonly="readonly"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>`</p>
  
  <p>I tried to change the delete-rows to be the same but because one has an id and the other doesn't it won't remove.
  Hope that makes sense.
  This then go into the database and I have a button to create a pdf, so the calculations need to be correct when deleting items.</p>
  
  <p>Many thanks.</p>