|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Junior Member
Iscritto dal: Aug 2006
Messaggi: 3
|
[javascript] condizione radio-button
Salve a tutti
vista l'inesperienza sono qui a chiedere un aiuto. Il seguente form va compilato in tutte le parti ma se si scegli il radio-button "SI" bisogna compilare anche il campo seguente altrimenti si salta a quello successivo. sono 2 giorni che qualcuno può aiutarmi?? GRAZIE ANTICIPATAMENTE. <html> <head> <title>Untitled</title> <script language="javascript"> function verifica() { var attivita=document.form1.attivita.value; var dove=document.form1.dove.value; var scelta=0; var sport=document.form1.sport.value; var SI=0; //Effettua il controllo sul campo ATTIVITà if ((attivita == "") || (attivita == "undefined")) { alert("Il campo ATTIVITA' è obbligatorio"); document.form1.attivita.focus(); return false; } //Effettua il controllo sul campo SCELTA' for(var i=0;i<document.form1.scelta.length;i++) { if(document.form1scelta.checked==true){ scelta=1 }; }; if (scelta==0){ alert("Scegli SI o NO"); return false; }; //Effettua il controllo sul campo DOVE for(var a=0;a<document.form1.scelta.length;a++){ if (document.form1.scelta[a].checked==true) { var SI=(document.form1.scelta[a].value); }; }; if (SI==1) { if ((dove == "") || (dove == "undefined")) { alert("Hai scelto SI, il campo DOVE è obbligatorio"); document.form1.dove.focus(); }; }; else if ((sport == "") || (sport == "undefined")) { alert("Il campo SPORT è obbligatorio"); document.form1.sport.focus(); return false; } else { document.form1.action = "dati.php"; document.form1.submit(); } } </script> </head> <body> <form action="" method="post" name="form1"> <table summary=""> <tr><td>Attività <input type="text" name="attivita" value="" /> </td> </tr> <tr><td>SI <input type="radio" name="scelta" value=1 /> NO <input type="radio" name="scelta" value=0 /> </td> </tr> <tr><td>Se si dove? <input type="text" name="dove" value="" /> </td> </tr> <tr><td>sport <input type="text" name="sport" value="" /></td> </tr> <tr><td colspan="4"> </td></tr> <tr><td align="center"><input type="button" value="Invia" onclick="verifica()" /> <input type="reset" name="canc" value="cancella" /></td> </tr> </table> </form> </body> </html> |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Sep 2007
Messaggi: 754
|
Tiè
Codice:
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function validateForm(){
var returnValue=true;
var msg="";
frm=document.getElementById('form1');
if(document.getElementById('attivita').value==""){
returnValue=false;
msg="Inserire l'attività";
}
if(document.getElementById("scelta").checked){
if(document.getElementById('dove').value=="" || document.getElementById('sport').value==""){
returnValue=false;
msg="Selezionare gli altri campi";
}
}
if(returnValue){
frm.action = "dati.php";
frm.submit();
}else{
alert(msg);
}
}
</script>
</head>
<body>
<form action="" method="post" name="form1" id="form1">
<table summary="">
<tr>
<td>Attività <input type="text" id="attivita" name="attivita" value="" /></td>
</tr>
<tr>
<td>
<input type="radio" id="scelta" name="scelta" value="0" />SI
<input type="radio" id="scelta" name="scelta" value="1" />NO
</td>
</tr>
<tr>
<td>Se si dove? <input type="text" id="dove" name="dove" value="" /> </td>
</tr>
<tr>
<td>Sport <input type="text" id="dove" name="sport" value="" /></td>
</tr>
<tr>
<td colspan="4"> </td></tr>
<tr>
<td align="center">
<input type="button" value="Invia" onclick="validateForm();" />
<input type="reset" name="canc" value="cancella" /></td>
</tr>
</table>
</form>
</body>
</html>
__________________
http://www.tevigroup.it/ |
|
|
|
|
|
#3 |
|
Junior Member
Iscritto dal: Aug 2006
Messaggi: 3
|
Grazie per la pronta rispota
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 18:01.



















