1. Registered User
Join Date
Mar 2013
Posts
4

help with for loop

Hi guys,
straight to the point.
i have a function called count. I'm trying to loop through the array or what is it called. But I only getting the last number in the array. It isnt calculating.
here is my code
function count()
{
var getal =document.getElementsByName("subtots");
var lengte = getal.length;
var som=0;
for(var i = 0; i <= lengte; i++ )
{
som=+ parseFloat(getal[i].value.replace(',','.')) || 0;
}
\$('#tota').val(som);
}

2. Try...
Code:
`som += parseFloat(getal[i].value.replace(',','.')) || 0;`
assuming "som" is a summation (sum)

3. Registered User
Join Date
Mar 2013
Posts
4
@JMRKER
I have founded myself, just before your aswer came up.
but thanks anyways

4. Originally Posted by siroj
@JMRKER
I have founded myself, just before your aswer came up.
but thanks anyways

So, for the benefit of others viewing this thread who might have a similar problem,
what was you final solution? What did you do to solve your original question?

5. Registered User
Join Date
Mar 2013
Posts
4
Code:
```var som = 0;
var getal =document.getElementsByName("subtots");
var subtotalen = Array.prototype.slice.call(getal);
for(i=0;i<subtotalen.length;i++)
{
som+= parseFloat(subtotalen[i].value.replace(',','.')) || 0;
}
\$('#tota').val(som.toFixed(2));

}```
Here it is, sorry I dont use forum often