suma en javascript
Publicado por vanessa (14 intervenciones) el 11/08/2016 00:32:39
quiero realiza la suma de una tabla dinamica tengo este codigo pero no funciona, quiero sumar los cubos, piezsas, toneladas.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function totalton(){
var totalc = document.getElementById('total_concepto').value;
//var cubos;
var ct;
for(i = 1; i <= totalc; i++){
cubos = document.getElementById('CUBOS'+i).value;
suma = parseInt(cubos) + parseInt(cubos);
}
alert(suma);
}
<table border="1" align="left">
<tr>
<td><strong>CUBOS</strong></td>
<td><strong>PIEZAS TOTALES</strong></td>
<td><strong>TONELADAS TOTALES</strong></td>
</tr>
<?php
$indice = 0;
do {
$indice = $indice + 1;
?>
<tr>
<td>
<input type="text" name="CUBOS" id="CUBOS<?php echo $indice; ?>" value="<?php echo $row_totaldescarga['CUBOS']; ?>" /></td>
<td>
<input type="text" name="PIEZAS" id="PIEZAS<?php echo $indice; ?>" value="<?php echo $row_totaldescarga['TOTAL PIEZAS']; ?>" /></td>
<td><input name="TONELADAS" id="TONELADAS<?php echo $indice; ?>" type="text" value="<?php echo $row_totaldescarga['TOTAL TONELADAS']; ?>" /></td>
</tr>
<?php } while ($row_totaldescarga = mysql_fetch_assoc($totaldescarga)); ?>
</table>
<input type="hidden" id="total_concepto" name="total_concepto" value="<?php echo $indice; ?>" />
Valora esta pregunta


0