How Much Does It Cost To Build A House

Dynamic Table Column Total with jQuery table { border-collapse: collapse; margin: 20px 0; } th, td { border: 1px solid #ccc; padding: 8px; text-align: center; } input { width: 100%; border: none; text-align: center; } button { margin: 10px 0; } .delete-row { background: #ff4444; color: white; border: none; padding: 5px 10px; cursor: pointer; }
Item Quantity Price Amount Actions
Total 91.50
$(document).ready(function() { // Function to calculate and update the total function calculateTotal() { var total = 0; $('.sum-col').each(function() { var val = parseFloat($(this).val()) || 0; total += val; }); $('#columnTotal').text(total.toFixed(2)); } // Auto-calculate Amount = Quantity × Price when Quantity or Price changes $('#myTable').on('input', '.qty, .price', function() { var row = $(this).closest('tr'); var qty = parseFloat(row.find('.qty').val()) || 0; var price = parseFloat(row.find('.price').val()) || 0; var amount = qty * price; row.find('.sum-col').val(amount.toFixed(2)); calculateTotal(); }); // If Amount is manually edited, just update the total (no override) $('#myTable').on('input', '.sum-col', function() { calculateTotal(); }); // Add new row $('#addRow').on('click', function() { var newRow = ` `; $('#myTable tbody').append(newRow); calculateTotal(); }); // Delete row $('#myTable').on('click', '.delete-row', function() { $(this).closest('tr').remove(); calculateTotal(); }); // Initial total calculation calculateTotal(); });
Scroll to Top