You are viewing limited content. For full access, please sign in.

Question

Question

Multiple calculations across a row

asked on February 22, 2016

I am trying to find a way to add two columns on a row where one of them is already a total of 2 columns. In the picture attached I need to add: Day total and Previous total to fill in the new month total. I use the following code to fill in the day total column:


$(document).ready(function () {
    $('.cf-table-block').on('blur', 'input', sumtotal);
    function sumtotal() {
        var sum = 0;
        $('.cf-table-block tbody tr').each(function () {
            var s = 0;
            $(this).find('.meal input').each(function () {
                s += parseNumber($(this).val());
            });
            $(this).find('.subtotal input').val(s);
            sum += s;
        });
        $('.total input').val(sum);
    }
    function parseNumber(n) {
        var f = parseFloat(n); //Convert to float number.
        return isNaN(f) ? 0 : f; //treat invalid input as 0;
    }
});
 

What do I need to add to make the rest of the calculations happen? The day total has a class of: subtotal, Previous total is class: prev_tot, and New month total is class:  new_tot

Question.png
Question.png (5.36 KB)
0 0

Replies

replied on February 26, 2016

Hi Aaron,

You just need to add one more line after "$(.total input').val(sum)" that adds the day total to the previous total and puts it into the new month:

$('.new_tot input').val($('.total input').val() + parseNumber($(this)find('.prev_tot input').val()));

Let me know if this works for you!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.