Problem with adding integers in an array
- by rshivers
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!