
21/06/2005, 05:56
|
 | Moderador extraterrestre | | Fecha de Ingreso: diciembre-2001 Ubicación: Madrid
Mensajes: 6.987
Antigüedad: 23 años, 2 meses Puntos: 61 | |
Prueba con esto: Código PHP: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
function suma(esto){
elementos=0;
total=0;
for(a=1;esto["precio"+a];a++){
numero=parseFloat(esto["precio"+a].value);
if(numero>0){
elementos+=1;
total+=numero;
}
}
media=total/elementos;
esto['total'].value=media;
}
</script></head>
<body>
<form action="medi2.asp" method="post" name="form" onSubmit="return suma(this)">
<p>NOMBRE
<input name="nombre" type="text" id="nombre">
</p>
<p>
Precio1
<input name="precio1" type="text" id="precio1" size="4" maxlength="4">
Punit1
<input name="punit1" type="text" id="punit1" size="4" maxlength="4">
</p>
<p>
Precio2
<input name="precio2" type="text" id="precio2" size="4" maxlength="4">
Punit2
<input name="punit2" type="text" id="punit2" size="4" maxlength="4">
</p>
<p>
Precio3
<input name="precio3" type="text" id="precio3" size="4" maxlength="4">
Punit2
<input name="punit3" type="text" id="punit3" size="4" maxlength="4">
</p>
<p>
Precio4
<input name="precio4" type="text" id="precio4" size="4" maxlength="4">
Punit2
<input name="punit4" type="text" id="punit4" size="4" maxlength="4">
</p>
<p>
Precio medio
<input name="total" type="text" id="total" size="6" maxlength="6">
</p>
<p>
<input type="submit" name="Submit" value="total">
</p>
</form>
</body>
</html>
Un saludo!
__________________ Cómo escribir
No hay pregunta tonta, sino tonto que quiere seguir en la ignorancia. |