Ciao a tutti, sto seguendo un corso di php e quindi sto facendo degli esercizi molto banali. Devo fare la somma di 2 numeri. L'html con i controlli javascript funziona correttamente ma quando clicco somma, si rallenta il browser e dopo un pò di secondi mi dice: la connessione è stata annullata. Sapete dirmi perchè? Grazie. Vi allego i codici
Codice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<Title>Somma</Title>
<meta name="author" content="Stefano">
<meta name="keywords" content="Informatica">
<meta name="keywords" content="Esercitazione">
<meta name="keywords" content="Html">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style1.css">
<script type="text/javascript">
function controllo(){
var numero1=document.f1.str1.value;
var numero2=document.f1.str2.value;
var n1=parseInt(numero1);
var n2=parseInt(numero2);
if(numero1 ==""||numero2 ==""){
window.alert("Non hai inserito tutti i valori");}
else if(n1!=numero1||n2!=numero2){
window.alert("Non hai inserito valori numerici");
}
else{
document.f1.action = "form2.php";
document.f1.submit();}
}
</script>
</head>
<body>
<H1>Somma di due numeri</H1>
<form name="f1" action="" method="get">
Primo numero: <input type="text" name="str1" value="" /></p>
Secondo numero: <input type="text" name="str2" value="" /></p>
<input type="button" value="Somma" onclick="controllo()"/>
<input type="reset" name="can" value="cancella" />
</p>
</form>
</body>
</html>
Codice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<Title>Somma</Title>
<meta name="author" content="Stefano">
<meta name="keywords" content="Informatica">
<meta name="keywords" content="Esercitazione">
<meta name="keywords" content="Html">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style1.css">
</head>
<body>
<H1>Somma di sue numeri</H1>
<?php
$a=$_GET("str1");
$b=$_GET("str2");
$c=$_GET("str1")+$_GET("str2");
echo "
$a+$b=$c</p>";
?>
</body>
</html>