I'm assigning the sum of a column in an HTML table to a JS (sum) variable, but when I print it on the screen I get a NaN, does anyone know why?
<tr>
<td style="background:#c4ffd6;" align="center" class="qtd_recuperado">
<?php echo "$recuperado_total"; ?>
</td>
</tr>
Then, in JS, I add:
<script type="text/javascript">
function sumQuantity() {
var elements = document.getElementsByClassName('qtd_recuperado');
var sum = 0;
for (i=0;i< elements.length;i++) {
sum = sum + parseFloat(elements[i].innerHTML);
};
document.getElementById('resultado').innerHTML = sum;
}
sumQuantity();
</script>
So I try to print, like this:
<td style="background:#c4ffd6;" align="center" class="qtd_recuperado" id="resultado"></td>