Robert Granlund
asked on
jQuery function to sum input fields
I have a function that displays the total certain text input fields.
<script>
$( window ).load(function() {
var sum = 0;
$(".calculate").each(function(){
var aValue = $(this).val();
sum += aValue;
$(".display-total").html('<strong>Total</strong> <span class="sale_price pull-right"><span class="cart_total">'+ sum + '</span></span>');
});
});
</script>
The issue is, is that The function ends up printing out each field input (Concatenating them) instead of adding them all up.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also change line 10 to
var aValue = $(this).html();
ASKER
OK, that worked.
@rgranlund - if the solution provided works, please "Accept" it.
ASKER
Open in new window