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>&nbsp;<span class="sale_price pull-right"><span class="cart_total">'+ sum + '</span></span>');
    });
});
</script>

Open in new window

The issue is, is that The function ends up printing out each field input (Concatenating them)  instead of adding them all up.
LVL 8
rgranlundAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hammadh Abdul RahmanCommented:
Just change line 6 to
sum += Number(aValue);

Open in new window


So that the script will be as follows.
<script>
 $( window ).load(function() {     
    var sum = 0;
    $(".calculate").each(function(){
        var aValue = $(this).val();
        sum += Number(aValue);
        $(".display-total").html('<strong>Total</strong>&nbsp;<span class="sale_price pull-right"><span class="cart_total">'+ sum + '</span></span>');
    });
});
</script>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgranlundAuthor Commented:
No I get 0 as a return; How would I write it to calculate the sum total of numbers contained inside of a div, instead. (not from an input field) The divs are being written to before this function runs.
<html>
<span id="this-display-total-{row_id}" class="calculate"></span>
</html>
<script>
 $( window ).load(function() { 
$("#this-display-total-{row_id}").html( premium_total );
    
    var sum = 0;
    $(".calculate").each(function(){
        var aValue = $(this).val();
        sum += Number(aValue);
        $(".display-total").html('<strong>Total</strong>&nbsp;<span class="sale_price pull-right"><span class="cart_total">'+ sum + '</span></span>');
    });
});
</script>

Open in new window

Hammadh Abdul RahmanCommented:
Also change line 10 to
var aValue = $(this).html();

Open in new window

rgranlundAuthor Commented:
OK, that worked.
nap0leonCommented:
@rgranlund - if the solution provided works, please "Accept" it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.