Ver Mensaje Individual
  #2 (permalink)  
Antiguo 31/05/2004, 04:10
soniagrande
 
Fecha de Ingreso: mayo-2004
Mensajes: 75
Antigüedad: 20 años, 1 mes
Puntos: 2
No se si es exactamente esto lo que decias, pero por si acaso te lo pongo:

<html>
<head>
<script language="JavaScript">
function calcularTotalParcial(index){
var cantidad = document.getElementsByName("cantidad")[index];
var precio = document.getElementsByName("precio")[index];
var total = document.getElementsByName("total")[index];
if((cantidad.value != "") && (precio.value != "")){
total.value = cantidad.value*precio.value;
calcularTotal();
}
else{
if(total.value != ""){
total.value = "";
calcularTotal();
}

}
}

function calcularTotal(){
var totales = document.getElementsByName("total");
var suma = 0;
for(var i=0; i<totales.length; i++){
if(totales[i].value != ""){
suma += totales[i].value*1;
}
}
document.getElementById("total_venta").value = suma;
}
</script>
</head>
<body>
<form>
<table>
<tr>
<td>Cantidad: <input type="text" name="cantidad" value="" onChange="calcularTotalParcial(0)"/></td>
<td>Precio: <input type="text" name="precio" value="" onChange="calcularTotalParcial(0)"/></td>
<td>total: <input type="text" name="total" value="" disabled="true"/></td>
</tr>
<tr>
<td>Cantidad: <input type="text" name="cantidad" value="" onChange="calcularTotalParcial(1)"/></td>
<td>Precio: <input type="text" name="precio" value="" onChange="calcularTotalParcial(1)"/></td>
<td>total: <input type="text" name="total" value="" disabled="true"/></td>
</tr>
<tr>
<td colspan="3">
<input type="text" name="total_venta" value=""/>
</td>
</table>
</form>
</body>
</html>