Ciao ragazzi,
stavo provando a fare un semplice modulo di registrazione con i campi obbligatori e i controlli sulla data sulla mail inserite (seguendo la guida Html). Ho provato i vari controlli funzionano tutti fino a quello della data sui giorni (mentre quello del formato funziona) e della mail quando premendo il tasto invia non accade nulla mentre per gli altri l'alert compare.
posto il codice, Cosa c'è di sbagliato?
grazie a tutti.codice:<html> <head> <title>Registrazione</title> <script language="javascript"> function Modulo() { // variabili associate ai campi del modulo var nome = document.modulo.nome.value; var cognome = document.modulo.cognome.value; var username = document.modulo.username.value; var password = document.modulo.password.value; var conferma = document.modulo.conferma.value; var email = document.modulo.email.value; var hobby = document.modulo.hobby.value; var nascita = document.modulo.nascita.value; var giorno = document.modulo.nascita.value.substring(0,2); var mese = document.modulo.nascita.value.substring(3,5); var anno = document.modulo.nascita.value.substring(6,10); var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/; if ((nome=="") || (nome=="undefined")) { alert("Il campo Nome è obbligatorio."); document.modulo.nome.focus(); return false; } else if ((cognome == "") || (cognome=="undefined")) { alert("Il campo Cognome è obbligatorio."); document.modulo.cognome.focus(); return false; } else if ((username == "") || (username=="undefined")) { alert("Il campo Username è obbligatorio."); document.modulo.username.focus(); return false; } else if ((password == "") || (password== "undefined")) { alert("Il campo Password è obbligatorio."); document.modulo.password.focus(); return false; } else if ((conferma == "") || (conferma== "undefined")) { alert("Il campo Conferma Password è obbligatorio."); document.modulo.conferma.focus(); return false; } else if (password != conferma) { alert("La password confermata è diversa da quella scelta. Controllare."); document.modulo.conferma.value=""; document.modulo.conferma.focus(); return false; } else if ((hobby == "") || (hobby =="undefined")) { alert("Il campo Hobby è obbligatorio."); document.modulo.hobby.focus(); return false; } else if ((nascita == "") || (nascita == "undefined")) { alert("Il campo Data di Nascita è obbligatorio."); document.modulo.nascita.focus(); return false; } else if (document.modulo.nascita.value.substring(2,3) !="/" || document.modulo.nascita.value.substring(5,6) !="/" || isNan(document.modulo.nascita.value.substring(0,2))|| isNan(document.modulo.nascita.value.substring(3,5))|| isNan(document.modulo.nascita.value.substring(6,10))) { alert("Inserire nascita nel formato corretto."); document.modulo.nascita.value=""; document.modulo.nascita.focus(); return false; } else if (giorno > 31) { // da qui sembra che i controlli non funzionino alert("Impossibile utilizzare un valore superiore a 31 per i giorni."); document.modulo.nascita.select(); return false; } else if (mese > 12) { alert("Impossibile utilizzare un valore superiore a 12 per i mesi."); document.modulo.nascita.value=""; document.modulo.nascita.focus(); return false; } else if (anno < 1900) { alert("Impossibile inserire un valore inferiore a 1900 per l'anno."); document.modulo.nascita.value=""; document.modulo.nascita.focus(); return false; } else if (!email_reg_exp.test(email) || (email=="") || (email == "undefined")) { alert("Inserire un indirizzo e-mail corretto."); document.modulo.email.focus(); return false; } else { document.modulo.submit(); } } </script> </head> <body bgcolor="yellow"> <h2>Benvenuto a </h2> <h3>Registrazione al sito</h3> n.b. Tutti i campi sono obbligatori. <form action="registrazione.jsp" name="modulo" method="post"> <table align="left" border="1"> <tr> <td>Nome</td> <td> <input type="text" name="nome"> </td> </tr> <tr> <td>Cognome</td> <td> <input type="text" name="cognome"> </td> </tr> <tr> <td>Username</td> <td> <input type="text" name="username"> </td> </tr> <tr> <td>Password</td> <td> <input type="password" name="password"> </td> </tr> <tr> <td>Conferma Password</td> <td> <input type="password" name="conferma"> </td> </tr> <tr> <td>Hobby</td> <td> <input type="text" name="hobby"> </td> </tr> <tr> <td>Data Di Nascita (gg/mm/aaaa) </td> <td> <input type="text" name="nascita"> </td> </tr> <tr> <td>E-Mail</td> <td> <input type="text" name="email"> </td> </tr> <td>Sesso</td> <td> <input type="radio" name="sesso" value="M" checked>M <input type="radio" name="sesso" value="F">F </td> <tr> <td colspan="2" align="center"> <input type="button" value="Invia" onClick="Modulo()" /> </td> </tr> </table> </form> </body> </html>
Ciao

Rispondi quotando
