Questi 2 campi obbligatori fanno uscire l'alert se il campo è vuoto e clicco Invia.
Il problema è che se dopo l'alert digito nel campo Nome, l'alert scatta al campo Messaggio
Codice PHP:
<script>
function controllaG() {
var f = document.forms.mioformG;
//.value == "" rende il campo obbligatorio, anche lo spazio bianco iniziale fa uscire l'alert
if(f.nome.value == "") {
document.getElementById('nomex').innerHTML = "Inserire il Nome";
f.nome.focus();
return false;
}
else {
document.getElementById('nomex').innerHTML = "";
}
//(Campo obbligatorio)
if(f.messaggio.value == "") {
document.getElementById('messaggiox').innerHTML = "Inserire il Messaggio";
f.messaggio.focus();
return false;
}
else {
document.getElementById('messaggiox').innerHTML = "";
}
return true;
}
</script>
</head>
<body>
<form method="post" name="mioformG" id="mioF" action="ins.php" onsubmit="return(controllaG());">
NOME * <input type="text" name="nome" onkeyup="controllaG()" /><span id="nomex"></span>
MESSAGGIO *<input type="text" name="messaggio" onkeyup="controllaG()" /><span id="messaggiox"></span>
<button type="submit" name="send" id="submit">Invia</button>
</form>