I have two tables in a timesheet, one is the timesheet daily entry the other is a separate table to record any hours used on machinery.
The Javascript calculation for the first timesheets works great, but when i try to use the same code for the machinery timesheet it fails.
$(document).ready(function () { $('.cf-table-block').on('blur', 'input', sumtotal); $(document).on('click', '.form-del-field', sumtotal); function sumtotal() { var hour = 0; var rate = 0; var total = 0; var subtotal = 0; $('.cf-table-block tbody tr').each(function () { hour = moment($(this).find('.hour input').val(), 'HHmm'); rate = moment($(this).find('.rate input').val(), 'HHmm'); subtotal = hour.diff(rate, 'hours', true); $(this).find('.total input').val(subtotal.toFixed(2)); total += subtotal; }); $('.Grandtotal input').val(total.toFixed(2)); } function parseNumber(n) { var f = parseFloat(n); //Convert to float number. return isNaN(f) ? 0 : f; //treat invalid input as 0; } }); // second jscript $(document).ready(function () { $('.cf-table-block').on('blur', 'input', sumtotal); $(document).on('click', '.form-del-field', sumtotal); function sumtotal() { var houra = 0; var ratea = 0; var totala = 0; var subtotala = 0; $('.cf-table-block tbody tr').each(function () { houra = parseNumber($(this).find('.houra input').val(), 'HHmm'); ratea = parseNumber($(this).find('.ratea input').val(), 'HHmm'); subtotala = (houra - ratea); $(this).find('.totala input').val(subtotala.toFixed(2)); totala += subtotala; }); $('.Grandtotal input').val(totala.toFixed(2)); } function parseNumber(n) { var f = parseFloat(n); //Convert to float number. return isNaN(f) ? 0 : f; //treat invalid input as 0; } });
The first Javascript is for the first table, the second javascript is the machinery table.