Ver Mensaje Individual
  #8 (permalink)  
Antiguo 09/11/2013, 11:44
Avatar de satjaen
satjaen
 
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Respuesta: Sumar resultados de una multiplicacion

A ver si te sirven estos ejemplos:

Código Javascript:
Ver original
  1. <html>
  2. <head>
  3. <script>
  4. function actualiza_total()
  5. {
  6.  
  7.     var cant = document.getElementById('cantidad').value;
  8.     var precio = document.getElementById('precio').value;
  9.     if(isNaN(cant) || isNaN(precio)) {
  10.         alert("Solo valores numericos por favor");
  11.         document.getElementById('cantidad').value = "";
  12.         document.getElementById('precio').value = "";
  13.         return;
  14.     }
  15.     document.getElementById('total').value = cant*precio;
  16. }
  17. </script>
  18. </head>
  19.  
  20. <body>
  21.     <input type="text" id="cantidad">
  22.     <input type="text" id="precio">
  23.     <input type="button" value="multiplicar" onClick="actualiza_total()">
  24.     <input type="text" id="total">
  25. </body>
  26. </html>

Código Javascript:
Ver original
  1. <html>
  2. <head>
  3. <script>
  4. function actualiza_total()
  5. {
  6.  
  7.     var cant = document.getElementById('cantidad').value;
  8.     var precio = document.getElementById('precio').value;
  9.     if(isNaN(cant) || isNaN(precio)) {
  10.         alert("Solo valores numericos por favor");
  11.         document.getElementById('cantidad').value = "";
  12.         document.getElementById('precio').value = "";
  13.         return;
  14.     }
  15.     document.getElementById('total').value = cant*precio;
  16. }
  17. </script>
  18. </head>
  19.  
  20. <body>
  21.     <input type="text" id="cantidad">
  22.     <input type="text" id="precio">
  23.     <input type="text" id="total" onfocus="actualiza_total()">
  24. </body>
  25. </html>

Un saludo

Última edición por satjaen; 09/11/2013 a las 12:10