ciao
ho un form, ho realizzato la validazione del campo nome e telefono(esistenza e presenza di soli numeri)
ora dovrei trovare in modo che il form non sia inviato se non è stata fatta una scelta nel menù a discesa (comuni),
inoltre vorrei aggiungere la possibilità al telefono di inserire sia numeri che i seguenti segni di separazione
spazio / - .
il codice del form (compresi javascript) è questo (ho evidenziato il select da validare):
[I]<script language="JavaScript">
<!--
function checkForm() {
var f=document.forms['newnews'];
if(f.nome.value=="" || f.nome.value=="undefined") {
window.alert("Non hai inserito il Nome");
f.nome.focus();
return false
}
if(f.telefono.value=="" || f.telefono.value=="undefined") {
window.alert("Metti il numero di telefono");
f.telefono.focus();
return false
}
return true
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_valida teForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' Deve essere inserito un indirizzo e-mail valido.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' deve contenere un numero (senza trattini o spazi o punti o barre).\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' Deve contenere un numero compreso fra '+min+' e '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' è richiesto.\n'; }
} if (errors) alert('Sono presenti i seguenti errori:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
<STYLE type=text/css>
<!--
-->
</STYLE>
</HEAD>
<BODY text=#000000 vLink=#000000 aLink=#000000 link=#000000 bgColor=#ffffff topMargin=10 marginwidth="10" marginheight="10">
</P>
<FORM name=newnews action="mailto:email@email.it?subject=Richiesta" method=post encType=text/plain onSubmit="return checkForm();">
<TABLE cellSpacing=0 cellPadding=2 width=390 align=center border=0>
<TBODY>
<TR>
<TD class=txt12b width=87 height=31>
<p align="center">Nome e cognome</p>
</TD>
<TD width=303 height=31>
<INPUT name=nome size=50>
</TD>
</TR>
<TR>
<TD width=87>
<p align="center"><SPAN class=txt12b>E-mail</SPAN></p>
</TD>
<TD width=303>
<INPUT size=50 value=" " name=mail>
</TD>
</TR>
<TR>
<TD width=87>
<p align="center">Telefono fisso</p>
</TD>
<TD width=303>
<INPUT name=telefono onBlur="MM_validateForm('telefono','','RisNum');re turn document.MM_returnValue" size=50>
</TD>
</TR>
<TR vAlign=top>
<TD height="56" colSpan=2>
<TABLE cellSpacing=0 cellPadding=0 width=390 align=center border=0>
<TBODY>
<TR>
<TD height="32">
<div align="center">
<select name="comuni">
<option value="Scegliere">Scegliere</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select> </div>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
<P align=center>
<INPUT type=submit value=Invia name=submit>
<INPUT type=reset value=Cancella name=reset>
</P>
</FORM>
grazie