I need to display the total result by adding the values that contain the value column:
var linha=document.getElementsByClassName("calcular");
var resultado=document.getElementById('total').innerHTML = 0;
for (var i=0; i < linha.length; i++) {
resultado += parseInt(linha[i].innerHTML);
}
document.getElementById("total").innerHTML = resultado;
table {
margin: 5px;
float: left;
width: 564px;
padding: 6px;
font-weight: bold;
font-size: 10pt;
color: white;
text-align: center;
}
th {
background-color: slateblue;
color: white;
}
tr td {
background-color: white;
color: black;
text-align: center;
}
<table>
<tr>
<th>ID</th>
<th>NOME</th>
<th>VALOR</th>
</tr>
<tr>
<td>01</td>
<td>Beltrano</td>
<td class="calcular">10.50</td>
</tr>
<tr>
<td>02</td>
<td>Fulano</td>
<td class="calcular">05.98</td>
</tr>
<tr>
<td>03</td>
<td>Ciclano</td>
<td class="calcular">25.00</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> TOTAL </td>
<td> </td>
<td id="total"> </td>
</tr>
</table>
Script works in part , but I could not get it to give me the total result with the decimal places (after the dot).
-
When should I get back: 41.48
At least this is how I imagine it should be.
If pulling this in a array
array, to interact between indexes can you solve it or am I wrong?
Or this solves with just some arithmetic expression