Ver Mensaje Individual
  #7 (permalink)  
Antiguo 27/01/2014, 13:01
alva_be21
 
Fecha de Ingreso: enero-2014
Mensajes: 9
Antigüedad: 10 años, 3 meses
Puntos: 0
De acuerdo Respuesta: sumar inputs dinamicos

Cita:
Iniciado por Gustavo72 Ver Mensaje
Si usaras jQuery, podrías hacer algo así:

Código HTML:
Ver original
  1. <script type="text/javascript" src="jquery.js"></script>
  2. <script type="text/javascript">
  3. var total=0;
  4. $(document).ready(function() {
  5.     $('input.cantidad').blur(function() { calcular_total() });
  6.     calcular_total();
  7. });
  8. function calcular_total() {
  9.     total=0;
  10.     $('input.cantidad').each(function() {
  11.         var v=parseFloat($(this).val());
  12.         if (isNaN(v)) {
  13.             v=0;
  14.             $(this).val(0);
  15.         }
  16.         total+=v;
  17.     });
  18.     $('div#total_monto_fiscal').html(total);
  19. }
  20. </head>
  21. <input type="text" class="cantidad" value="5"><br>
  22. <input type="text" class="cantidad" value="6"><br>
  23. <input type="text" class="cantidad" value="7">
  24. </form>
  25. <div id="total_monto_fiscal"></div>
  26. </body>
  27. </html>

Si! ya lo adecue a mis inputs y funciona, muchas gracias Gustavo72