Problem with adding integers in an array

Posted by rshivers on Stack Overflow See other posts from Stack Overflow or by rshivers
Published on 2010-05-28T19:02:57Z Indexed on 2010/05/28 19:12 UTC
Read the original article Hit count: 116

Filed under:
|

Hello again,

I'm trying to loop through my totals in order to get a grand total for my web app. So far the code I am working with is the following:

function calcAllFields() {
    var name = parseFloat($('div [name = total[]]').text());
    var totArray = $.makeArray(name);
    var total = 0;
        for (var i = 0; i < totArray.length; i++) {
                total += totArray[i];
                }
    $("#target1").text(total);
}

Instead of adding integers, something is being read as a string. Say I want to add 200 + 50, instead of 250 I get 20050. Could anyone please point out what I'm doing wrong? Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery