I have a form (absence request) that has a table containing a number field (number of hours requested). The user can click a link to add more lines to the table, and I have a number field that contains the sum of all hours requested. The script I have for the sum is posted below, but what I need is to incorporate script to allow decimal (2 places) values in both the table number field and the sum number field. I see some script across the Answers site related to currency, etc., but I don't know how to incorporate the script to allow decimals with the script I already have. Any help to get this functionality added to my form would be greatly appreciated.
$(document).ready(function () { $('.cf-table-block').on('blur', 'input', sumtotal); function sumtotal() { var s = 0; $('.sum input').each(function () { s += parseNumber($(this).val()); }); $('.total input').val(s); } function parseNumber(n) { var f = parseFloat(n); //Convert to float number. return isNaN(f) ? 0 : f; //treat invalid input as 0; } });