# How to add all var sub totals to get display a grand total currently getting nan [Answered]RSS

## 1 reply

Last post Apr 09, 2016 06:40 PM by vested

• vested

None

0 Points

2 Posts

### How to add all var sub totals to get display a grand total currently getting nan

Apr 09, 2016 02:55 PM|vested|LINK

How to add all var sub totals to get display a grand total currently getting nan

not sure what is going wrong, any help is appreciated

script>

\$(document).ready(function () {
\$(".calcrow input").keyup(multInputs);

function multInputs() {
var mult = 0;
// for each row:
\$(".calcrow").each(function () {
// get the values from this row:
var \$sm8jb = \$('.sm8jb', this).val();
var \$sm8fx = \$('.sm8fx', this).val();
var \$totalsm8 ='\$' +(\$sm8jb * 1 ) * (\$sm8fx * 1)
if ( \$sm8jb <= 20 ) { \$totalsm8 = '\$' + 0 } else { \$totalsm8 ='\$' +((\$sm8jb * 1 ) * (\$sm8fx * 1)-10);}

var \$vujb = \$('.vujb', this).val();
var \$vufx = \$('.vufx', this).val();
var \$totalvu ='\$' +((\$vujb * 1 ) * (\$vufx * 1))
if ( \$vujb <= 2 ) { \$totalvu = '\$' + 0 } else { \$totalvu = '\$' +((\$vujb * 1 ) * (\$vufx * 1)-40);}

var \$val1 = \$('.val1', this).val();
var \$val2 = \$('.val2', this).val();
var \$total ='\$' +(\$val1 * 1 ) * (\$val2 * 1)

\$('.multTotal',this).text(\$total);
\$('.sm8Total',this).text(\$totalsm8);
\$('.vuTotal',this).text(\$totalvu);

mult += \$total;

});
\$('.grandTotal').text(mult);

}

});

• vested

None

0 Points

2 Posts

### Re: How to add all var sub totals to get display a grand total currently getting nan

Apr 09, 2016 06:40 PM|vested|LINK

correct way here

<script>
\$(document).ready(function () {
\$(".calcrow input").keyup(multInputs);

function multInputs() {
var mult = 0;
// for each row:
\$(".calcrow ").each(function () {
// get the values from this row:
var val1 = parseFloat(\$('.val1', this).val() || 0);
var val2 = parseFloat(\$('.val2', this).val() || 0);
var sm8 = parseFloat(\$('.sm8', this).val() || 0);
var vu = parseFloat(\$('.vu', this).val() || 0);

var total = (val1 * 1) * (val2 * 1);

var sm8T = sm8 <= 20 ? 0 : (sm8 * 1) * (val2 * 1)-10;
var vuT= vu <= 2 ? 0 : (vu * 1) * (val2 * 1)-40;

\$('.vuT',this).text('\$' + vuT);
\$('.sm8T',this).text('\$' + sm8T);
\$('.multTotal',this).text('\$' + total);

mult += sm8T+vuT+total;
});
\$("#grandTotal").text('\$' + mult);
}

});

</script>