Ver Mensaje Individual
  #4 (permalink)  
Antiguo 10/09/2011, 21:14
tazzwt
 
Fecha de Ingreso: marzo-2010
Mensajes: 432
Antigüedad: 14 años, 2 meses
Puntos: 11
Respuesta: Un getElementById dinamico realizar suma

Tengo algo de codigo con el getElementsByName pero no funciona, siempre da como resultado cero. No suma los valores de los Input


Código Javascript:
Ver original
  1. <script language="javascript">
  2.  
  3. function sumar()
  4. {
  5. var total = 0;
  6. var coleccion = document.getElementsByName("myInput[]");
  7.  
  8. for (i = 0; elem = coleccion[i]; i++) {
  9.  
  10.     total += (parseInt(elem[i].value));
  11.    
  12. }
  13.  
  14. alert(total);
  15.  
  16.    
  17. }
  18.  
  19. </script>
  20.  
  21.  
  22. <input name="myInput" type="text" value="1" size="20"><br>
  23. <input name="myInput" type="text" value="2" size="20"><br>
  24. <input name="myInput" type="text" value="4" size="20"><br>
  25. <br>
  26. <input name="mybutton" type="button" onclick="sumar()">
__________________
Libro de HTML 5 + codigo fuente bajar aqui.