
Originariamente inviata da
Markus85
Ciao . Usato il campo "id" e ricavato i valori tramite "GetElementById()"
..................FUNZIONA!
Posto il codice completo per completezza.
codice:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Pagina della Registrazione</title>
<link href="http://127.0.0.1:8080/GMarkusStore-war/FogliStileCSS/Foglio1.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
function ControlloCampi() {
var nome = document.getElementById("Nome").value;
var cognome = document.getElementById("Cognome").value;
var codiceFiscale = document.getElementById("CodiceFiscale").value;
//Espressione regolare del Codice Fiscale :
var patternCF = /^[a-zA-Z]{6}[0-9]{2}[a-zA-Z][0-9]{2}[a-zA-Z][0-9]{3}[a-zA-Z]$/;
var indirizzo = document.getElementById("Indirizzo").value;
var cap = document.getElementById("CAP").value;
//Espressione regolare del CAP :
var patternCap = /^[0-9]{5}$/;
var localita = document.getElementById("Localita").value;
var provincia = document.getElementById("Provincia").value;
//Espressione regolare della Provincia :
var patternProvincia = /^[a-zA-Z]{2}$/;
var stato = document.getElementById("Stato").value;
var telefono = document.getElementById("Telefono").value;
var email = document.getElementById("Email").value;
//Espressione regolare dell'Email :
var patternEmail = /^([a-zA-Z0-9_\.\-])+@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
var username = document.getElementById("Username").value;
var password = document.getElementById("Password").value;
var ripetiPassword = document.getElementById("RipetiPassword").value;
if ((nome == "") || (!isNaN(nome)) ||(nome == "undefined")){
alert("Il campo Nome è Obbligatorio!");
document.getElementById("Nome").value = "";
document.getElementById("Nome").focus();
return false;
}
else if ((cognome == "") || (!isNaN(cognome)) || (cognome == "undefined")){
alert("Il campo Cognome è Obbligatorio!");
document.getElementById("Cognome").value = "";
document.getElementById("Cognome").focus();
return false;
}
else if ( !patternCF.test(codiceFiscale) || (codiceFiscale == "") || (codiceFiscale == "undefined")){
alert("Inserire un Codice Fiscale Valido!")
document.getElementById("CodiceFiscale").focus();
return false;
}
else if ((indirizzo == "") || (indirizzo == "undefined")){
alert("Il campo Indirizzo è Obbligatorio");
document.getElementById("Indirizzo").focus();
return false;
}
else if ( !patternCap.test(cap) || (cap == "") || (cap == "undefined")){
alert("Inserire un CAP Valido!");
document.getElementById("CAP").focus();
return false;
}
else if ((localita == "") || (!isNaN(localita)) || (localita == "undefined")){
alert("Inserire una Località Valida!");
document.getElementById("Localita").focus();
return false;
}
else if (!patternProvincia.test(provincia) || (provincia == "") || (provincia == "undefined")){
alert("Inserire una Provincia Valida!");
document.getElementById("Provincia").value = "";
document.getElementById("Provincia").focus();
return false;
}
else if ((stato == "") || (!isNaN(stato)) || (stato == "undefined")){
alert("Inserire uno Stato!");
document.getElementById("Stato").value = "";
document.getElementById("Stato").focus();
return false;
}
else if ((telefono == "") || (isNaN(telefono)) || (telefono == "undefined")){
alert("Inserire un Numero di Telefono Valido!");
document.getElementById("Telefono").focus();
return false;
}
else if ((email == "") || (!patternEmail.test(email)) || (email == "undefined")){
alert("Inserire una Email Valida!");
document.getElementById("Email").focus();
return false;
}
else if ((username == "") || (username == "undefined")){
alert("Inserire un Username!");
document.getElementById("Username").focus();
return false;
}
else if ((password == "") || (password == "undefined")){
alert("Inserire una Password!");
document.getElementById("Password").focus();
return false;
}
else if ((ripetiPassword == "") || (ripetiPassword == "undefined")){
alert("Digita Nuovamente la Password che hai Scelto");
document.getElementById("RipetiPassword").focus();
return false;
}
else if (password != ripetiPassword){
alert("La Password Confermata è Diversa da quella Scelta , Controllare!");
document.getElementById("RipetiPassword").value = "";
document.getElementById("RipetiPassword").focus();
return false;
}
else {
alert("Dati OK");
}
}
</script>
</head>
<body background="http://127.0.0.1:8080/GMarkusStore-war/Immagini/img_background/sfondo-paginaWebSpazio.gif">
<%@ include file="../header.jsp" %>
<br>
<button class="bottoneNonCliccabile">Registrati</button>
<br>
<br>
<table class="tabelle">
<form name="FormRegistrazione" method="post">
<tr>
<td>
<font class="testoBiancoFluorescente">Nome :</font>
</td>
<td>
<input class="caselleInput" type="text" name="Nome" id="Nome">
</td>
</tr>
<tr>
<td>
<font class="testoBiancoFluorescente">Cognome :</font>
</td>
<td>
<input class="caselleInput" type="text" name="Cognome" id="Cognome">
</td>
</tr>
<tr>
<td>
<font class="testoBiancoFluorescente">Codice Fiscale :</font>
</td>
<td>
<input class="caselleInput" type="text" name="CodiceFiscale" id="CodiceFiscale">
</td>
</tr>
<tr>
<td>
<font class="testoBiancoFluorescente">Indirizzo :</font>
</td>
<td>
<input class="caselleInput" type="text" name="Indirizzo" id="Indirizzo">
</td>
</tr>
<tr>
<td>
<font class="testoBiancoFluorescente">CAP :</font>
</td>
<td>
<input class="caselleInput" type="text" name="CAP" id="CAP">
</td>
</tr>
<tr>
<td>
<font class="testoBiancoFluorescente">Località :</font>
</td>
<td>
<input class="caselleInput" type="text" name="Località" id="Localita">
</td>
</tr>
<tr>
<td>
<font class="testoBiancoFluorescente">Provincia :</font>
</td>
<td>
<input class="caselleInput" type="text" name="Provincia" id="Provincia">
</td>
</tr>
<tr>
<td>
<font class="testoBiancoFluorescente">Stato :</font>
</td>
<td>
<input class="caselleInput" type="text" name="Stato" id="Stato">
</td>
</tr>
<tr>
<td>
<font class="testoBiancoFluorescente">Telefono :</font>
</td>
<td>
<input class="caselleInput" type="text" name="Telefono" id="Telefono">
</td>
</tr>
<tr>
<td>
<font class="testoBiancoFluorescente">Email :</font>
</td>
<td>
<input class="caselleInput" type="text" name="Email" id="Email">
</td>
</tr>
<tr>
<td>
<font class="testoBiancoFluorescente">Username :</font>
</td>
<td>
<input class="caselleInput" type="text" name="Username" id="Username">
</td>
</tr>
<tr>
<td>
<font class="testoBiancoFluorescente">Password :</font>
</td>
<td>
<input class="caselleInput" type="password" name="Password" id="Password">
</td>
</tr>
<tr>
<td>
<font class="testoBiancoFluorescente">Ripeti Password :</font>
</td>
<td>
<input class="caselleInput" type="password" name="RipetiPassword" id="RipetiPassword">
</td>
</tr>
<tr></tr>
<tr>
<td></td>
<td></td>
<td>
<input class="bottone" type="button" value="Registra" onClick="ControlloCampi()">
</td>
</tr>
<tr height="5"></tr>
</form>
</table>
</body>
</html>
Grazie
Ciao