ho notato che oggi.getMonth() prendi un mese in meno del dovuto...oggi ad esempio segna 4 mentre maggio è 5...quindi...
con la tua data infatti ora funzia.....:mavieni: :mavieni:Codice PHP:
<html>
<head>
<title></title>
<script>
function CalcoloEta() {
var annonascita=parseInt(document.myForm.anno.value);
var mesenascita=parseInt(document.myForm.mese.value);
if(isNaN(annonascita)){
alert("Anno non numerico!");
}
else if(isNaN(mesenascita)){
alert("Mese non numerico!");
}
else{
var oggi=new Date();
var annocorrente=oggi.getFullYear();
var mesecorrente=oggi.getMonth()+1;
var totAnni=0;
var totMesi=0;
totAnni=annocorrente-annonascita;
totMesi=mesecorrente-mesenascita;
if(totMesi<0){
totAnni--;
totMesi=12-(totMesi*-1);
}
alert("Hai esattamente "+(totAnni)+" anni e "+(totMesi)+" mesi.")
}
}
</script>
</head>
<body>
<form name="myForm">
Anno Nascita: <input type="text" name="anno"></p>
Mese Nascita: <input type="text" name="mese"></p>
<input type="button" value="anni" onclick="CalcoloEta()">
</form>
</body>
</html>