I have this code where I'm getting the values correctly from the form (I made a alert
with each item and it's getting right). But when saving the variable the sum is not right, when I give alert
in sum it appears NaN
. Here's the snippet of my code:
function somaPesos() {
var soma = 0;
var itens = document.getElementsByClassName("soma");
for (i = 0; i < itens.length; i++) {
var item = parseInt(itens[i].value);
alert(item);
soma = soma + item;
}
alert(soma);
return false;
}