Muy buenas estoy creando una calculadora con php i el problema es que el reset, para borrar los campos no funciona, vuelve a dejar los que tenia antes.. Aki el codigo:
<html>
<head>
<style>
body {
background-color:yellow;
}
body form {
border:3px solid purple;
width:300px;
text-align:center;
margin-left:500px;
margin-top:100px;
background-color:white;
padding:10px 10px 10px 10px;
}
body h1 {
margin-left:530px;
color:green;
}
</style>
<title>Calculadora</title>
</head>
<body>
<h1><s>Calculadora</s></h1>
<?
if ( (!isset($_POST['op'])) && (!isset($_POST['o1'])) && (!isset($_POST['o2'])) ) {
echo "<form action='calculadora.php' method='POST' enctype='multipart/form-data' name=form>
Operand 1:<input type='number' name='o1' /><br />
Operand 2:<input type='number' name='o2' /><br />
Operacio:<select name=op><option value=suma>suma</option><option value=resta>resta</option><option value=multiplicacio>multiplicacio</option><option value=divisio>divisio</option></select><br />
Resultat:<input type='number' name='resultat' /><br />
<input type='submit' value='Calcular'>
<input type='reset' value='Limpiar'>
<form>";
} else if ( (isset($_POST['op'])) && (isset($_POST['o1'])) && (isset($_POST['o2'])) ) {
switch ($_POST['op']) {
case "suma":
$resultat=$_POST['o1']+$_POST['o2'];
echo "<form action='calculadora.php' method='POST' enctype='multipart/form-data' name=form>
Operand 1:<input type='number' name='o1' value=$_POST[o1] /><br />
Operand 2:<input type='number' name='o2' value=$_POST[o2] /><br />
Operacio:<select name=op><option value=suma>suma</option><option value=resta>resta</option><option value=multiplicacio>multiplicacio</option><option value=divisio>divisio</option></select><br />
Resultat:<input type='number' name='resultat' value=$resultat /><br />
<input type='submit' value='Calcular'>
<input type='reset' value='Limpiar'>
<form>";
break;
case "resta":
$resultat=$_POST['o1']-$_POST['o2'];
echo "<form action='calculadora.php' method='POST' enctype='multipart/form-data' name=form>
Operand 1:<input type='number' name='o1' value=$_POST[o1] /><br />
Operand 2:<input type='number' name='o2' value=$_POST[o2] /><br />
Operacio:<select name=op><option value=suma>suma</option><option value=resta>resta</option><option value=multiplicacio>multiplicacio</option><option value=divisio>divisio</option></select><br />
Resultat:<input type='number' name='resultat' value=$resultat /><br />
<input type='submit' value='Calcular'>
<input type='reset' value='Limpiar'>
<form>";
break;
case "multiplicacio":
$resultat=$_POST['o1']*$_POST['o2'];
echo "<form action='calculadora.php' method='POST' enctype='multipart/form-data' name=form>
Operand 1:<input type='number' name='o1' value=$_POST[o1] /><br />
Operand 2:<input type='number' name='o2' value=$_POST[o2] /><br />
Operacio:<select name=op><option value=suma>suma</option><option value=resta>resta</option><option value=multiplicacio>multiplicacio</option><option value=divisio>divisio</option></select><br />
Resultat:<input type='number' name='resultat' value=$resultat /><br />
<input type='submit' value='Calcular'>
<input type='reset' value='Limpiar'>
<form>";
break;
case "divisio":
if ($_POST['o2']==0) {
echo "No es pot dividir entre 0";
echo"<br /><form action='calculadora.php' method='POST' enctype='multipart/form-data' name=form>
<input type='submit' value='Tornar'>
<form>";
break;
} else {
$resultat=$_POST['o1']/$_POST['o2'];
echo "<form action='calculadora.php' method='POST' enctype='multipart/form-data'>
Operand 1:<input type='number' name='o1' value=$_POST[o1] /><br />
Operand 2:<input type='number' name='o2' value=$_POST[o2] /><br />
Operacio:<select name=op><option value=suma>suma</option><option value=resta>resta</option><option value=multiplicacio>multiplicacio</option><option value=divisio>divisio</option></select><br />
Resultat:<input type='number' name='resultat' value=$resultat /><br />
<input type='submit' value='Calcular'>
<input type='reset' value='Limpiar'>
<form>";
break;
}
}
}
?>
</body>
</html>
Si algien sabe como acerlo se lo agradezco! :)