Ver Mensaje Individual
  #6 (permalink)  
Antiguo 27/01/2014, 10:22
Avatar de Gustavo72
Gustavo72
 
Fecha de Ingreso: abril-2008
Ubicación: -32.956045,-60.661355
Mensajes: 197
Antigüedad: 16 años
Puntos: 9
Respuesta: sumar inputs dinamicos

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>
__________________
Saludos.

Gustavo