Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function() {
- $("#invoiceitems tbody tr").each(function() {
- $(this).change(function() {
- updateTotal();
- });
- });
- });
- function updateTotal() {
- //Calculate Subtotal for each item
- var quantity = $('.quantity').val();
- var price = $('.price').val();
- var subtotal = parseInt(quantity) * parseFloat(price);
- $('.subtotal').text(subtotal);
- //Calculate Grand Total
- var sum = 0;
- $('.linetotal').each(function() {
- sum += parseFloat($(this).text());
- });
- $('#grandTotal').html(parseFloat(sum));
- }
- <table>
- <tr>
- <td>
- <input type="text" name="unitCost[]" id="unitCost_1" value="15.99" class="editable"/>
- </td>
- <td>
- <input type="text" name="quantity[]" id="quantity_1" value="1" class="editable"/>
- </td>
- </tr>
- <tr>
- <td>
- <input type="text" name="unitCost[]" id="unitCost_2" value="2.50" class="editable"/>
- </td>
- <td>
- <input type="text" name="quantity[]" id="quantity_2" value="1" class="editable"/>
- </td>
- </tr>
- </table>
- $(document).ready(function() {
- updateTotal();
- $(".editable").live("change", function() {
- updateTotal();
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement