Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/12/2011, 13:08
Bier
 
Fecha de Ingreso: enero-2002
Mensajes: 1.174
Antigüedad: 22 años, 3 meses
Puntos: 21
Respuesta: Sumar 2 campos por getElementById

Encontré este código que lo hace por Id, solo que no logro incorporarlo a la primera fucnción:


Código HTML:
Ver original
  1. <script type="text/javascript">
  2.  
  3. function DoSum()
  4. {
  5.   document.getElementById("Sum").value =
  6.     parseInt(document.getElementById("No1").value) +
  7.     parseInt(document.getElementById("No2").value) +
  8.     parseInt(document.getElementById("No3").value) +
  9.     parseInt(document.getElementById("No4").value) +
  10.     parseInt(document.getElementById("No5").value)
  11. }
  12.  
  13.  
  14. <input type="text" id="No1" style="width:20px" value="10"/> +
  15. <input type="text" id="No2" style="width:20px" value="20"/> +
  16. <input type="text" id="No3" style="width:20px" value="30"/> +
  17. <input type="text" id="No4" style="width:20px" value="40"/> +
  18. <input type="text" id="No5" style="width:20px" value="50"/> =
  19. <input type="text" id="Sum" style="width:30px"/>
  20. <input type="button" value="Sum" onclick="DoSum()"/>