Hi,
I am looking to do a simple calculation of Hour*Rate = total for a table, but this table will be a multi-row.
My current code works for only the first row, and when trying to add another row it inputs the total value of the first row into the second row, third etc...
$(document).ready(function () {
$('.cf-table-block').on('blur', 'input', sumtotal);
function sumtotal() {
var hour = 0;
var rate = 0;
$('.cf-table-block tbody tr').each(function () {
$(this).find('.hour input').each(function () {
hour += parseNumber($(this).val());
});
$(this).find('.rate input').each(function () {
rate += parseNumber($(this).val());
});
});
$('.total input').val(hour * rate);
}
function parseNumber(n) {
var f = parseFloat(n); //Convert to float number.
return isNaN(f) ? 0 : f; //treat invalid input as 0;
}
});