I have a form that I cannot get the calculations to work correctly using JavaScript in Forms 9.1.0. Each row in the table has 4 columns (Cash, In-Kind, Grant, and Total). Each has a CSS class assigned to it respectively (revenueCash, revenueInKind, revenueGrant, revenueLineTotal). There is also a Grand Total field at the bottom of the form with the CSS value of revenueGrandTotal.
I need to add the Cash, InKind, and Grant totals together and display the line total in the Total field per row. I then need to add the Total fields from each row and display it in the Grand Total field.
I have used the following JavaScript, but it is not calculating at all when a value is entered. I'm sure I am missing something simple, but any help would be appreciated.
//Calculate row totals $('cf-table-block').on('blur', 'input', sumtotal); function sumtotal() { var sum = 0; $('.cf-table-block tbody tr').each (function () { var s = 0; s = parseNumber($(this).find('.revenueCash input').val()) + parseNumber($(this).find('.revenueInKind input').val()) + parseNumber($(this).find('.revenueGrant input').val()); $(this).find('.revenueLineTotal input').val(s); sum += s; }); $(".revenueGrandTotal input").val(sum); } function parseNumber(n) { var f = parseFloat(n); //Convert to float number return isNaN(f) ? 0 : f; //Treat invalid input as 0; }