asked on October 28, 2015
•
Show version history
I have a table in a form that does calculation per row , i need to do a total of the "Total Price"
outside the table like it shows on the image.
At the moment it seems to be totaling the wrong inputs
$(document).ready(function () {
$('.cf-table-block').on('blur', 'input', sumtotal);
$('.totaltotal').on('blur', 'input', sumtotal);
function sumtotal() {
var sum = 0;
$('.cf-table-block tbody tr').each(function () {
var s = 0;
$(this).find('.price input').each(function () {
s += parseNumber($(this).val());
})
$(this).find('.subtotal input').val(s);
sum += s;
var subtotal = $(this).find(".subtotal input").val();
var unitPrice = $(this).find(".rate input").val();
var totalPrice = subtotal * unitPrice;
$(this).find(".total input").val(totalPrice);
});
$(".totaltotal input").val(sum);
var subtotalprice = parseNumber($(".totaltotal input").val();
}
function parseNumber(n) {
var f = parseFloat(n); //Convert to float number.
return isNaN(f) ? 0 : f; //treat invalid input as 0;
}
});
0
0