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

Question

Question

How do we Display the total value from rows in a table where radio button is selected

asked on July 22, 2019 Show version history

I have a Number field that I would like to display the total value of a dollar amount when a radio button is selected.

In the example below, in each row where 'Y' is checked, we would like Forms to take the value under the Total Cost column for that row and display the total in the Confirmed Purchase field above the table.

 

So, 1,994.79+1,421.37 should be 'grabbed' and then 3,416.16 should display in the Confirmed Purchase field.

I tried adapting another posted solution that used check boxes, but that didn't work.

I used a sample from Laserfiche and it is giving me the total of every row.  I am trying to see if I can have Forms only include the rows that have a radio button 'Y' checked.

 

Here is the code I currently have:

$(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.sum').each(function () {
            var s = 0;
            $(this).find('input').each(function () {
                s += parseNumber($(this).val());
            });
            $(this).find('.subtotal input').val(s);
            sum += s;
        });
        $('.total 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;
    }
});

 

Radio Button.jpg
Radio Button.jpg (58.62 KB)
0 0

Answer

SELECTED ANSWER
replied on July 22, 2019

You don’t need JavaScript, you can do this with a SUMIF calculation.

It would be something like

=SUMIF(Table.Column1,”Yes”,Table.Column2)

1 0

Replies

replied on July 23, 2019

Thank you!  That was much easier.

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

Sign in to reply to this post.