JavaScript - suma en javascript

 
Vista:
sin imagen de perfil
Val: 14
Ha aumentado su posición en 4 puestos en JavaScript (en relación al último mes)
Gráfica de JavaScript

suma en javascript

Publicado por vanessa (11 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
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

suma en javascript

Publicado por DAVID (36 intervenciones) el 15/08/2016 13:46:46
Hola,
Porque no la vas acumulando en el bucle? Algo del tipo:
1
$sum_cubos+=$row_totaldescarga['CUBOS'];
Y al final del bucle lo pones, no?
Y porque estas usando campos INPUT?? Con poner el valor te vale, no?

Un saludo,
David
diseño web madrid
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar