Ver Mensaje Individual
  #8 (permalink)  
Antiguo 03/12/2015, 12:43
Osvaldo_Jacobo
 
Fecha de Ingreso: diciembre-2015
Ubicación: Pachuca Hidalgo
Mensajes: 6
Antigüedad: 8 años, 5 meses
Puntos: 1
Respuesta: problema con operaciones datos dinamicos

listo ya funciona todo muy bien muchas gracias por la ayuda...les dejo el codigo por si a alguien le sirve

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2. function calcular(){
  3.             var importe=parseFloat($(this).find("input[name=importe]").val());
  4.             var cantidad=$(this).find("input[name=cantidad]").val();
  5.             $(this).find("[class=total]").html((parseFloat(importe)*parseFloat(cantidad)).toFixed(2));
  6.  
  7.             // calculamos el total de todos los grupos
  8.             var total=0;
  9.             $(".grupo .total").each(function(){
  10.                 total=total+parseFloat($(this).html());
  11.             })
  12.             $(".total .total").html(total.toFixed(2));
  13.            
  14. }
  15. $(document).ready(function(){
  16.     calcular();
  17.  $(".grupo").keyup(calcular);
  18. });
  19.     </script>
Código HTML:
Ver original
  1. <table align="center" style="text-align:center;" width="90%" border="1" cellspacing="0">
  2.   <tr>
  3.     <th scope="col">nombre</th>
  4.     <th scope="col">cantidad</th>
  5.     <th scope="col">precio</th>
  6.     <th scope="col">Subtotal</th>
  7.   </tr>
  8.     <?php do { ?>
  9.   <tr class="grupo">
  10.       <td><?php echo $row_carrito['nombre_producto']; ?></td>
  11.       <td><input type="text" name="cantidad" value="<?php echo $row_carrito['cantidad']; ?>" autocomplete="off" /></td>
  12.       <td><input style="border:0; background:none; width:55px; text-align:center;" readonly="readonly" type="text" name="importe" value="<?php echo $row_carrito['precio']; ?>" /></td>
  13.       <td><span class="total"><?php echo $row_carrito['precio']; ?></span></td>
  14.     </tr>
  15.     <?php } while ($row_carrito = mysql_fetch_assoc($carrito));  ?>
  16.     <tr class="total">
  17.       <td>&nbsp;</td>
  18.       <td>&nbsp;</td>
  19.       <td>total:</td>
  20.       <td class="total"><span class="total">0</span></td>
  21.     </tr>
  22.     </div>

Última edición por Osvaldo_Jacobo; 03/12/2015 a las 13:02