Este es el código del cual debería tomar los valores:
Código PHP:
$i=0;
while($row=mysql_fetch_assoc($resultado)){
echo "<tr>";
echo "<td align='center'><input type='text' size='3' value='".$row['cantidad']."' id='cantidad$i'> </td>";
echo "<td align='center'><input type='text' size='3' value='".obtenerPrecio($row['id_producto'])."' id='precio$i' ></td>";
echo "</tr>";
$i++;
}
Y este el script que debería calcular el precio:
Código HTML:
onLoad=calcular();
function calcular(){
var total=document.getElementById("filas").value;
for(var i=0;i<=total-1;i++){
idcaja="cantidad"+i;
idcaja2="precio"+i;
var precio=document.getElementById(idcaja).value;
precio=parseInt(precio);
var cantidad=document.getElementById(idcaja2).value;
cantidad=parseInt(cantidad);
precio=precio*cantidad;
precioTotal=precioTotal+precio;
}
document.getElementById('precioTotal').innerHTML=precioTotal;
}



