Scusate se posto uno script intero ma voglio capire perhè il numero 1 va e il numero 2 mi da errore quando secondo me dovrebbe essere il contrario.
Segno in rosso la parentesi che causa i miei dubbi.
Codie 1
codice:
<!--
function Modulo() {
// Variabili associate ai campi del modulo
var nome = document.modulo.nome.value;
var cognome = document.modulo.cognome.value;
var indirizzo = document.modulo.indirizzo.value;
var citta = document.modulo.citta.value;
var provincia = document.modulo.provincia.value;
var cap = document.modulo.cap.value;
var iva = document.modulo.iva.value;
var telefono = document.modulo.telefono.value;
var consenso = document.modulo.consenso.value;
var email = document.modulo.email.value;
var sitoweb = document.modulo.sitoweb.value;
var username = document.modulo.username.value;
var password = document.modulo.password.value;
var conferma = document.modulo.conferma.value;
// Espressione regolare dell'email
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 ((indirizzo == "") || (indirizzo == "undefined")) {
alert("Il campo Indirizzo è obbligatorio.");
document.modulo.indirizzo.focus();
return false;
}
else if ((citta == "") || (citta == "undefined")) {
alert("Il campo Città è obbligatorio.");
document.modulo.citta.focus();
return false;
}
else if ((provincia == "") || (provincia == "undefined")) {
alert("Il campo Provincia è obbligatorio.");
document.modulo.provincia.focus();
return false;
}
else if ((cap == "") || (cap == "undefined")) {
alert("Il campo C.a.p. è obbligatorio.");
document.modulo.cap.focus();
return false;
}
else if ((telefono == "") || (telefono == "undefined")) {
alert("Il campo Telefono è obbligatorio.");
document.modulo.telefono.focus();
return false;
}
else if ((iva== "") || (iva == "undefined")) {
alert("Il campo P.Iva / C.F. è obbligatorio.");
document.modulo.iva.focus();
return false;
}
else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
alert("Inserire un indirizzo e-mail corretto.");
document.modulo.email.select();
return false;
}
else if (document.modulo.consenso.checked==false) {
alert("Le condizioni sulla privacy devono essere accettate.");
document.modulo.consenso.focus();
return false;
}
else if ((username== "") || (username == "undefined")) {
alert("Il campo Username è obbligatorio.");
document.modulo.username.focus();
return false;
}
else if ((password== "") || (password == "undefined") || (document.getElementById("password").value.length < 6)) {
alert("Il campo Password è obbligatorio e deve essere di almeno 6 caratteri.");
document.modulo.password.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;
}
//INVIA IL MODULO
else {
document.modulo.action = "sendData.asp";
document.modulo.submit();
}
}
//-->
</script>
Codice 2
codice:
<!--
function Modulo() {
// Variabili associate ai campi del modulo
var nome = document.modulo.nome.value;
var cognome = document.modulo.cognome.value;
var indirizzo = document.modulo.indirizzo.value;
var citta = document.modulo.citta.value;
var provincia = document.modulo.provincia.value;
var cap = document.modulo.cap.value;
var iva = document.modulo.iva.value;
var telefono = document.modulo.telefono.value;
var consenso = document.modulo.consenso.value;
var email = document.modulo.email.value;
var sitoweb = document.modulo.sitoweb.value;
var username = document.modulo.username.value;
var password = document.modulo.password.value;
var conferma = document.modulo.conferma.value;
// Espressione regolare dell'email
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 ((indirizzo == "") || (indirizzo == "undefined")) {
alert("Il campo Indirizzo è obbligatorio.");
document.modulo.indirizzo.focus();
return false;
}
else if ((citta == "") || (citta == "undefined")) {
alert("Il campo Città è obbligatorio.");
document.modulo.citta.focus();
return false;
}
else if ((provincia == "") || (provincia == "undefined")) {
alert("Il campo Provincia è obbligatorio.");
document.modulo.provincia.focus();
return false;
}
else if ((cap == "") || (cap == "undefined")) {
alert("Il campo C.a.p. è obbligatorio.");
document.modulo.cap.focus();
return false;
}
else if ((telefono == "") || (telefono == "undefined")) {
alert("Il campo Telefono è obbligatorio.");
document.modulo.telefono.focus();
return false;
}
else if ((iva== "") || (iva == "undefined")) {
alert("Il campo P.Iva / C.F. è obbligatorio.");
document.modulo.iva.focus();
return false;
}
else if ((!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
alert("Inserire un indirizzo e-mail corretto.");
document.modulo.email.select();
return false;
}
else if (document.modulo.consenso.checked==false) {
alert("Le condizioni sulla privacy devono essere accettate.");
document.modulo.consenso.focus();
return false;
}
else if ((username== "") || (username == "undefined")) {
alert("Il campo Username è obbligatorio.");
document.modulo.username.focus();
return false;
}
else if ((password== "") || (password == "undefined") || (document.getElementById("password").value.length < 6)) {
alert("Il campo Password è obbligatorio e deve essere di almeno 6 caratteri.");
document.modulo.password.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;
}
//INVIA IL MODULO
else {
document.modulo.action = "sendData.asp";
document.modulo.submit();
}
}
//-->
</script>
Non è corretto mettere la doppia parentesi visto che in chiusura c'è?