I have a mileage reimbursement form that calculates a miles field in each row of a table. We have had the request to have the ability to mark a row as roundtrip. I like the idea, but I'm not sure how to implement it. Basically if the roundtrip checkbox is selected, it would need to grab the value of the miles field for that row and multiply it by 2 and replace the miles value. Below is the JavaScript we currently have (thanks to Answers).
//Start Add row mile fields together $('.cf-table-block').on('blur', 'input', sumtotal); if ($('.subtotal').length > 0) { $('.cf-table-block').on('blur', 'input', rowtotal); } function sumtotal() { var sum = 0; $('td.sum').each(function () { var s = 0; $(this).find('input').each(function () { s += parseNumber($(this).val()); }) $(this).find('.subtotal input').val(s); sum += s; }); $('.total input').val(sum); } function rowtotal() { var sum = 0; $('.cf-table-block tbody tr').each(function () { var s = 0; $(this).find('.sum input').each(function () { s += parseNumber($(this).val()); }) $(this).find('.subtotal input').val(s); sum += s; }); } function parseNumber(n) { var f = parseFloat(n); //Convert to float number. return isNaN(f) ? 0 : f; //treat invalid input as 0; } //End Add row mile fields together