I was successful in implementing javascript to add up colomns in a table and assigning the result to a number field outside the Table.
It was all working fine, but whenever I enter a 4 digit value into colomns, the calculation all goes berserk.
Lets say I enter 4 values into column1 like 1000, 1 , 1, 1. The result I am getting is 4 now.
I think the code is taking the 4 digit number as single digit.
Javascript is given below for the same.
$(document).ready(function () {
$('.cf-table-block').on('blur', 'input', sumtotal);
if ($('.subtotal').length > 0) {
$('.cf-table-block').on('blur', 'input', rowtotal);
}
function sumtotal() {
var sum = 0;
$('td.S1').each(function () {
var s = 0;
$(this).find('input').each(function () {
s += parseNumber($(this).val());
});
$(this).find('.subtotal input').val(s);
sum += s;
});
$('.A 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;
}
});