este es mi codigo javascript:
Código:
y este es el html:<script type="text/javascript">
$(document).ready(function(){
$(".grupo").keyup(function()
{
var importe=$(this).find("input[name=precio]").value();
var cantidad=$(this).find("input[name=cantidad]").value();
$(this).find("[class=total]").html(parseInt(importe)*parseInt(cantidad));
// calculamos el total de todos los grupos
var total=0;
$(".grupo .total").each(function(){
total=total+parseInt($(this).html());
})
$(".total .total").html(total);
});
});
</script>
Código HTML:
<table width="90%" border="1" cellspacing="0"> <tr> <th scope="col">nombre</th> <th scope="col">cantidad</th> <th scope="col">precio</th> <th scope="col">Subtotal</th> </tr> <?php do { ?> <div class="grupo"><tr> <td><?php echo $row_carrito['nombre_producto']; ?></td> <td><input type="text" name="cantidad" value="<?php echo $row_carrito['cantidad'];?>"/></td> <td>$<input type="text" name="precio" value="<?php echo $row_carrito['precio'];?>"/></td> <td><span class="total">0</span></td> </tr></div> <?php } while ($row_carrito = mysql_fetch_assoc($carrito)); ?> <div class="total"><tr> <td> </td> <td> </td> <td>total:</td> <td><div class="total"><span class="total">0</span></div></td> </tr> </div> </table>


