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

Question

Question

Forms 9.2.1 - Total a Collection and then Multiply it by a value outside of the Collection

asked on June 6, 2016

The goal of this form is to first subtotal the values inputted within a collection. Then take that subtotal value and multiply it by a rate value inputted by the user to get the Grand Total.

Collection Subtotal x Rate = Grand Total

$(document).ready(function () {
    $('.cf-collection-block').on('blur', 'input', sumtotal);
        function sumtotal() {
        var sum = 0;
        $('.cf-collection-block ul').each(function () {
            var s = 0;
            $(this).find('.hour input').each(function () {
                s += parseNumber($(this).val());
            });
            $(this).find('.subtotal input').val(s);
            sum += s;
        });
           $(".subtotal input").val(sum);
                  var subtotalPrice = parseNumber($(".subtotal input").val());
        var rateAmount = parseNumber($(".rate input").val());
        $(".total input").val((subtotalPrice * rateAmount).toFixed(2));
    }
    function parseNumber(n) {
        var f = parseFloat(n); //Convert to float number.
        return isNaN(f) ? 0 : f; //treat invalid input as 0;
    }
});

The subtotal values are working correctly but I have not been able to integrate the "Rate" into the equation.

Please let me know if any additional information may be helpful.

Your assistance is appreciated!

Cynthia Stewart

0 0

Answer

SELECTED ANSWER
replied on June 6, 2016

You can add following code to trigger the calculation when user input rate:

 $('.rate input').on('blur', sumtotal);

 

1 0

Replies

replied on June 6, 2016

Thank you!! That did it.

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

Sign in to reply to this post.