aggiunta di checkbox obbligatorio

marcussem

Nuovo Utente
10 Dic 2005
12
0
0
www.lanostraisola.net
Ciao, è da giorni che cerco di documentarmi per l'aggiunta di un campo checkbox obbligatorio per inviare il modulo ma ahimè date le mie poche conoscienze non riesco ad avere una finestra di alert come per gli altri campi testuali e dunque risulta ininfluente il la selezione del campo checkbox che tgra l'altro mi occorre per la Privacy.
Se qualcuno mi illumina posto il codice.
Mille Grazie Ciao

Questo il form
<form method=post onsubmit="return controllo(this);">
<tr>
<td>Nome e cognome</td>
<td><input type=text name=nome value='<%=server.htmlencode(nome)%>'></td>
</tr>
<tr>
<td>Via e numero</td>
<td><input type=text name=ind value='<%=server.htmlencode(ind)%>'></td>
</tr>
<tr>
<td>Comune</td>
<td><input type=text name=comune value='<%=server.htmlencode(comune)%>'></td>
</tr>
<tr>
<td>Provincia</td>
<td><input type=text name=prov value='<%=server.htmlencode(prov)%>'></td>
</tr>
<tr>
<td>CAP</td>
<td><input type=text name=cap value='<%=server.htmlencode(cap)%>'></td>
</tr>
<tr>
<td>Telefono*</td>
<td><input type=text name=telefono value='<%=server.htmlencode(telefono)%>'></td>
</tr>
<tr>
<td>Indirizzo e-mail</td>
<td><input type=text name=email value='<%=server.htmlencode(email)%>'></td>
</tr>
<tr>
<td colspan="2"><font color="#0000FF">Se il destinatario è
diverso da chi ordina completa anche sotto</font></td>
</tr>
<tr>
<td>Spedire a</td>
<td>
<input type=text name=spedire value='<%=server.htmlencode(spedire)%>'></td>
</tr>
<tr>
<td>Indirizzo completo</td>
<td>
<input type=text name=indcompl value='<%=server.htmlencode(indcompl)%>'></td>
</tr>
<tr>
<td>
<img border="0" src="images/busta1.jpg" width="50" height="50" align="right">Scrivi biglietto</td>
<td>
<input type=text name=biglietto value='<%=server.htmlencode(biglietto)%>'></td>
</tr>
<tr>
<td>
<p style="margin-top: 0; margin-bottom: 0">
<span style="font-size: 12.0pt; line-height: 115%; font-family: 'Times New Roman',serif">
<b>SI,</b> acconsento che i miei dati siano raccolti </span></p>
<p style="margin-top: 0; margin-bottom: 0">
<span style="font-size: 12.0pt; line-height: 115%; font-family: 'Times New Roman',serif">
e trattati
da
xxxxxxxxxx per i fini </span></p>
<p style="margin-top: 0; margin-bottom: 0">
<span style="font-size: 12.0pt; line-height: 115%; font-family: 'Times New Roman',serif">
dichiarati nella
<a style="color: blue; text-decoration: underline; text-underline: single" href="http://www.xxxxxxxxxxxx/privacy.asp">
<span style="color:blue">Informativa Privacy </span></a>. </span></p>
<p style="margin-top: 0; margin-bottom: 0">
<span style="font-size: 12.0pt; line-height: 115%; font-family: 'Times New Roman',serif">
D.lgs
196/2003, Codice in materia
di </span></p>
<p style="margin-top: 0; margin-bottom: 0">
<span style="font-size: 12.0pt; line-height: 115%; font-family: 'Times New Roman',serif">
protezione dei dati personali</span></p>

<td>
<p align="center"><input type="checkbox" name="consenso" value="consenso"> <tr>
<td colspan=2 align=center><input type="submit" name="accetto" value="Invio" > &nbsp; </td>
</tr>
</form>
 
forse è meglio completare il post con il controllo campi che già eseguo sul form, ma che come detto non riesco a far controllare il campo checkbox o radio che sia (è l'ultimo campo così come quello nel form).
Grazie ciao

<script type="Text/JavaScript">
function controllo(f) {
if (f.nome.value=="") {
alert("Campo Nome obbligatorio.");
f.nome.focus();
return false;
}
if (f.ind.value=="") {
alert("Campo Via e numero obbligatorio.");
f.ind.focus();
return false;
}
if (f.comune.value=="") {
alert("Campo Comune obbligatorio.");
f.comune.focus();
return false;
}
if (f.prov.value=="") {
alert("Campo Provincia obbligatorio.");
f.prov.focus();
return false;
}
if (f.stato.value=="") {
alert("Campo Nazione obbligatorio.");
f.stato.focus();
return false;
}
if (f.cap.value=="") {
alert("Campo CAP obbligatorio.");
f.cap.focus();
return false;
}
if (f.telefono.value=="") {
alert("Campo Telefono obbligatorio.");
f.telefono.focus();
return false;
}
if (f.email.value=="") {
alert("Campo Indirizzo e-mail obbligatorio.");
f.email.focus();
return false;
}
if (f.consenso.value=="") {
alert("Consenso privacy obbligatorio.");
f.consenso.focus();
return false;
}
return true;

}

</script>
 
:) Ciao, se può interessare l'enigma (per me!!) l'ho risolto mettendo il radio (meglio del check) come prima voce del form e così pure il suo controllo e modificando le voci name e value;

form:
<input type="radio" name="consenso" value="SI"></td>
<input type=text name=nome value='<%=server.htmlencode(nome)%>'>
'e tutto il resto

controllo:
<script type="Text/JavaScript">
function controllo(f) {
if (!f.consenso.checked) {
alert("Accettare la normativa sulla privacy prima di procedere!");
f.consenso.focus();
return false;
}
if (f.nome.value=="") {
alert("Campo Nome obbligatorio.");
f.nome.focus();
return false;
}
ecc ecc

Grazie a tutti ciao :beer:
 

Discussioni simili