Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Convalida e Controllo due campi

    Ciao ragazzi,
    avrei bisogno di realizzare uno script che mi convalidi un form prima dell'invio dei dati, praticamente la convalida dovrebbe funzionare così:

    I campi interessati sono 3:
    - categoriapre
    - categoria
    - sottocategoria

    se categoriapre e sottocategoria sono entrami compilati lo script deve convalidare il form o rinviare al campo che tra i 2 non è compilato. In alternativa se è compilato solo il campo categoria il form può convalidare l'invio dei dati.

    A tal scopo mi sono scritto questa sintassi ma non essendo un esperto di java ho evidentemente cannato qualcosa: sapete darmi una manozza?
    codice:
    <html>
    <head>
    <title>Pannello gestione Prodotti - www.diemmepi.it </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style>
    .linkgnr {font-family: verdana, arial; font-size: 7.8pt; color: #FFFFCC; text-decoration:none}
    .linkgnr:hover {font-family: verdana, arial; font-size: 7.8pt; color: #FFFFCC; text-decoration:none}
    input {font-family: verdana, arial; font-size: 8pt}
    select {font-family: verdana, arial; font-size: 8pt}
    textarea {font-family: verdana, arial; font-size: 8pt}
    .link2 {font-family: arial; font-size: 8.4pt; color: #666666; font-weight: bold; text-decoration:underline}
    .link2:hover {font-family: arial; font-size: 8.4pt; color: #666666; font-weight: bold; text-decoration:underline}
    .link3 {font-family: arial; font-size: 8pt; color: white;  text-decoration:none}
    .link3:hover {font-family: arial; font-size: 8pt; color: white; text-decoration:none}
    .Stile1 {
    	color: #FF6600;
    	font-weight: bold;
    	font-family: verdana, arial;
    	font-size: 11px;
    }
    .formtext {
    	font-family: Verdana, Arial, Helvetica, sans-serif;
    	font-size: 13px;
    	color: #000000;
    }
    </style>
    </head>
    <script language="javascript">
     <!--
      function Modulo() {
         // Variabili associate ai campi del modulo
         var categoriapre = document.modulo.categoriapre.value;
         var categoria = document.modulo.categoria.value;
         var sottocategoria = document.modulo.sottocategoria.value;
    	 //Effettua il controllo sul campo NOME
            if ((categoriapre == "") & (sottocategoria == "true")) {
               alert("Indicare un nome per la categoria");
               document.modulo.categoriapre.focus();
               return false;
            }
            //Effettua il controllo sul campo COGNOME
            else if ((sottocategoria == "") & (categoriapre == "true")) {
               alert("Indicare la sottocategoria.");
               document.modulo.sottocategoria.focus();
               return false;
            }
            //INVIA IL MODULO
            else {
               document.modulo.action = "categoria.asp";
               document.modulo.submit();
            }
      }
     //-->
    </script> 
    <body bgcolor="#FFFFFF" text="#000000">
    
    
    
    
    <table width="520" height="0" border="0" align="center" cellpadding="0" cellspacing="0" background="../images/asp/punto_grigio.gif">
      <tr> 
        <td valign="top" bgcolor="#000066" height="11">[img]../images/asp/angolo_sx_home_top.gif[/img]</td>
        <td bgcolor="#000066" height="11" width="63"></td>
      </tr>
      <tr> 
        <td colspan="2" height="2">[img]../images/asp/punto_bianco.jpg[/img]</td>
      </tr>
      <tr valign="top"> 
        <td colspan="2"> 
          <table width="520" height="0" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr> 
              <td> <table border="1" width="100%" height="24" cellpadding="4" cellspacing="0" bordercolorlight="#808080" bordercolordark="#FFFFFF" bgcolor="#CCCCCC">
                  <tr> 
                    <td bgcolor="#FF6600" height="8"><font size="2" face="Arial, Helvetica, sans-serif" color="#FFFFFF"> 
                      Aggiungi nuova Categoria -</font><font color="#FFFFFF" size="1" face="Arial, Helvetica, sans-serif"> 
                      ( </font><font size="1" face="Arial, Helvetica, sans-serif"><a href="pannello.asp?user=<%=request.QueryString("user")%>&pwd=<%=request.QueryString("pwd")%>&sid=<%=request.QueryString("sid")%>" class="link3">torna 
                      al pannello principale</a> <font color="#FFFFFF">)</font></font></td>
                  </tr>
                </table></td>
            </tr>
            <tr> 
              <td height="2">[img]../images/asp/punto_grigio.jpg[/img]</td>
            </tr>
            <tr> 
              <td height="0" align="center" valign="middle"> <form action="categoria.asp" method="post" name="modulo" id="modulo">
                  <table width="500" border="0" align="center" cellpadding="0" cellspacing="2">
                    <tr> 
                      <td height="5" colspan="6"></td>
                    </tr>
                    <tr valign="middle"> 
                      <td width="500" height="24" bgcolor="#F5F5F5" class="formtext"> 
                        Categorie Presenti:</td>
                      <td width="382" height="24" colspan="5" bgcolor="#CCCCCC"><font size="2" face="Arial, Helvetica, sans-serif"> 
                        <select name="categoriapre" class="menu">
                          <option selected>-- seleziona --</option>
                          <%
    Set Con=Server.CreateObject("adodb.connection")
    Con.Open("DRIVER=xxxx)
    
    Set objrs = Con.Execute("select * from categoria")				  
    
    Do while not objrs.eof
    %>
                          <option value="<%=(objrs.Fields.Item("id").Value)%>"><%=(objrs.Fields.Item("categ").Value)%></option>
                          <%
    objrs.movenext
    Loop
    %>
                        </select>
                        </font></td>
                    </tr>
                    <tr valign="middle"> 
                      <td width="500" height="24" bgcolor="#F5F5F5" class="formtext"> 
                        Nuova Categoria:</td>
                      <td height="24" colspan="5" bgcolor="#CCCCCC"><font size="2" face="Arial, Helvetica, sans-serif"> 
                        <input name="categoria" type="text" id="categoria" value="" size="40">
                        </font> </td>
                    </tr>
                    <tr valign="middle"> 
                      <td width="500" height="24" bgcolor="#F5F5F5" class="formtext"> 
                        Nuova Sottocategoria:</td>
                      <td height="24" colspan="5" bgcolor="#CCCCCC"> 
                        <input name="sottocategoria" type="text" id="sottocategoria" value="" size="40">
                         </font><font size="2" face="Arial, Helvetica, sans-serif"> 
                        </font></td>
                    </tr>
                    <tr> 
                      <td colspan="3"height="5"></td>
                    </tr>
                    <tr> 
                      <td height="25" colspan="6" align="center" valign="middle" bgcolor="#CCCCCC"> 
                                  <input type="hidden" name="action" value="reg">
                                  <input type="hidden" name="sid" value="<%=request("sid")%>">
                                  <input type="hidden" name="id" value="<%=request("id")%>">
                                  <input type="hidden" name="user" value="<%=request("user")%>">
                                  <input type="hidden" name="pwd" value="<%=request("pwd")%>">
                                  <input type="submit" name="Submit" value="Registra" onClick="Modulo()"> </td>
                    </tr>
                    <tr> 
                      <td colspan="6"></td>
                    </tr>
                  </table>
                </form></td>
            </tr>
            <tr> 
              <td height="0"> <table width="50" height="15" border="0" align="center" cellpadding="0" cellspacing="0">
                  <tr> 
                    <td></td>
                  </tr>
                </table></td>
            </tr>
          </table>
    	  
          
        </td>
      </tr>
      <tr> 
        <td colspan="2" height="2" valign="bottom">[img]file:///D|/Lavori/Lineon/sito/images/asp/punto_bianco.jpg[/img]</td>
      </tr>
      <tr> 
        <td width="457" height="10" valign="bottom" bgcolor="#000066"></td>
        <td valign="bottom" align="right" bgcolor="#000066" height="10" width="63"> 
          <div align="right">[img]../images/asp/angolo_sx_login_bottom.jpg[/img]</div>
        </td>
      </tr>
    </table>
    <%
    objrs.close
    con.close
    set objrs=nothing
    set con=nothing
    %>
    
    
    
    
    </body>
    </html>

  2. #2
    prova così:

    codice:
    function controllo(f) {
     var ok1=false;
     var ok2=false;
     if (f.categoria.value!="") return true;
     ok1=(f.categoriapre.value=="") ? false : true;
     ok2=(f.sottocategoria.value=="") ? false : true;
     if (!ok1) {
      alert("Compilare il campo categoriapre.");
      f.categoriapre.focus();
      return false;
     }
     if (!ok2) {
      alert("Compilare il campo sottocategoria.");
      f.sottocategoria.focus();
      return false;
     }
     return true;
    }
    da richiamare così:

    codice:
    <form name="f" onsubmit="return controllo(this);">
    ciao

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.