Salve come da titolo ho un form :
codice:
<html>
<head>
<title></title>
<script type="text/javascript">
function checkinclusive() {
"use strict";
check_notnull('nome');
check_notnull('cognome');
check_cellulare('cellulare');
}
function check_allok() {
"use strict";
if ((nome === 1) && (cognome === 1) &&(cellulare === 1) ) {
document.getElementById('invio').style.display = "inline";
}
else {
document.getElementById('invio').style.display = "none";
}
}
function check_notnull(campo) {
var dati = eval("document.dati."+campo+".value;");
lab = campo+'1';
if(dati == ""){
document.getElementById(lab).innerHTML = 'Campo obbligatorio';
eval("document.dati."+campo+".focus();");
eval (campo+"=0;");
}
else {
document.getElementById(lab).innerHTML = 'ok';
eval (campo+"=1;");
}
check_allok();
}
function check_cellulare(campo5) {
var dati = eval("document.dati."+campo5+".value;");
lab = campo5+'1';
if( (dati.length<8) || (dati.length>12) || isNaN(dati) ){
document.getElementById(lab).innerHTML = ' Inserire un numero di cellulare';
eval("document.dati."+campo5+".focus();");
cellulare=0;
}else{
document.getElementById(lab).innerHTML = 'ok';
cellulare=1;
}
check_allok();
}
</script>
</head>
<body onload="checkinclusive()">
<form name="dati" action="inviadati.php" method="post" onSubmit="return false;">
<label>Nome</label>
<input id="nome" name="nome" type="text" class="input-text" maxlength="50" style="width:250px" onkeydown='check_notnull("nome")'/> <div id="nome1" ></div><br/>
<label>Cognome</label>
<input name="cognome" type="text" class="input-text" maxlength="50" style="width:250px" onkeydown='check_notnull("cognome")' /> <div id="cognome1" ></div><br/>
<label>Numero Cellulare</label>
<input name="cellulare" type="text" class="input-text" maxlength="50" style="width:250px" onkeyup='check_cellulare("cellulare")' /> <div id="cellulare1" ></div><br/>
<button class="redirect_page" type="submit" data-animation-type="bounce" style="width:250px" id="invio" data-animation-duration="1" onclick="document.dati.submit()">SALVA I DATI </button>
</form>
</body>
</html>
quando sono all'esterno dei campi se non ho tutti i campi ok il form non viene inviato , ma se sto scrivendo all'interno di un campo e premo invio ,anche non avendo compilato correttamente il campo il form viene inviato....