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

Question

Question

Updating totals in forms

asked on April 4, 2017

We have a form that totals a value in a table.  The calculation works fine as long as the user does not need to remove a row.  If they do, the total is not updated unless they click into the field with the res-sum class.  How can I change the code to update automatically?

$(document).ready(function () {
    $(document).on('blur change', '.res-sum input', sumtotal);
  
    function sumtotal() {
        var s = 0;
        $('.res-sum input').each(function () {
            s += parseNumber($(this).val());
        });
        $('.res-total input').val((s).toFixed(2));
    }
    function parseNumber(n) {
        var f = parseFloat(n); //Convert to float number.
        return isNaN(f) ? 0 : f; //treat invalid input as 0;
    }
})

 

0 0

Replies

replied on April 4, 2017

Add this so that the totals recalculate on the X click

 $(document).on('click', '.form-del-field', sumtotal); // calculate again when the user clicks the X to remove a roww

 

1 0
replied on April 4, 2017

That works great.  Thanks Raul!

0 0
replied on April 4, 2017

What version of Forms are you running? Have you tried the built-in ability in the Total field to do the calculation?

0 0
replied on April 4, 2017

We're using 10.2. 

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

Sign in to reply to this post.