daily pastebin goal
94%
SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.     $("#invoiceitems tbody tr").each(function() {
  3.         $(this).change(function() {
  4.             updateTotal();
  5.         });
  6.     });
  7. });
  8.  
  9. function updateTotal() {
  10.  
  11.     //Calculate Subtotal for each item
  12.     var quantity = $('.quantity').val();
  13.     var price = $('.price').val();
  14.     var subtotal = parseInt(quantity) * parseFloat(price);
  15.     $('.subtotal').text(subtotal);
  16.     //Calculate Grand Total
  17.     var sum = 0;
  18.     $('.linetotal').each(function() {
  19.         sum += parseFloat($(this).text());
  20.     });
  21.     $('#grandTotal').html(parseFloat(sum));
  22. }​
  23.    
  24. <table>
  25. <tr>
  26. <td>
  27. <input type="text" name="unitCost[]" id="unitCost_1" value="15.99" class="editable"/>
  28. </td>
  29. <td>
  30. <input type="text" name="quantity[]" id="quantity_1" value="1" class="editable"/>
  31. </td>
  32. </tr>
  33. <tr>
  34. <td>
  35. <input type="text" name="unitCost[]" id="unitCost_2" value="2.50" class="editable"/>
  36. </td>
  37. <td>
  38. <input type="text" name="quantity[]" id="quantity_2" value="1" class="editable"/>
  39. </td>
  40. </tr>
  41. </table>
  42.    
  43. $(document).ready(function() {
  44.     updateTotal();
  45.  
  46.     $(".editable").live("change", function() {
  47.         updateTotal();
  48.     });
  49. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top