I have a problem with a code that I am developing in javascript.
function sumaTotales()
{
var totalsum=0;
var j=document.getElementById("padre").childNodes;
console.log(j);
for(i=1;i<j.length;i++)
{
totalsum=+Number(j[i].value);
console.log(totalsum);
}
}
the problem is that when I try to add the value of the fields, the fields are not added to the total variable, but are overwritten.
3 dynamicgeneration.html:41:14
4 dynamicgeneration.html:41:14
Huyyyyyyy you almost have it, change this line and you will see what magic:
for this:
I explain what is happening:
In the first you are assigning a positive number, that is, if
Number(j[i].value
it is 5, what you are doing is this:In the second line what you are doing is incrementing the value of totalsum the value
Number(j[i].value)
.