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

Question

Question

Multiply JS Calculated Total by Percentage

asked on August 20, 2015

We are creating a tuition reimbursement form where the employee is reimbursed 90% of the total cost of the course taken.  We have been able to calculate a subtotal for each row in the course table and calculate a grand total, but have not been able to successfully multiply the grand total by .9 to calculate the amount the employee would be reimbursed.  Any assistance would be greatly appreciated. 

Form Table:

JS / CSS Screen showing table:

JS currently being used:

$(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('.price 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;
    }
});

0 0

Answer

SELECTED ANSWER
replied on August 20, 2015

Hello Glenn, 

 

This code takes the same sum put into the grand total and multiplies it by 0.9.

 

$(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('.price input').each(function () {

                s += parseNumber($(this).val());

            });

            $(this).find('.subtotal input').val(s);

            sum += s;

        });

        $('.total input').val(sum);

        $('#q16 input').val(sum * 0.9);

    }

    function parseNumber(n) {

        var f = parseFloat(n); //Convert to float number.

        return isNaN(f) ? 0 : f; //treat invalid input as 0;

    }

});

Since the labels in the picture are off, I wasn't sure if q16 or q18 was the id of the 90% reimbursement field.

1 0

Replies

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

Sign in to reply to this post.