Ver Mensaje Individual
  #14 (permalink)  
Antiguo 05/06/2010, 13:46
Avatar de maycolalvarez
maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 9 meses
Puntos: 1532
Respuesta: Formulario que no comprueva los campos vacios... :S

aveces a no se le pierde la cabeza, colocaste mal los nombres, por ejemplo sendfrom en vez de sendform, de seguro esto te funciona:

Código Javascript:
Ver original
  1. <script language="JavaScript">
  2. function check()
  3. {
  4.     var checked=true;
  5.     var pattern=/.*\@.*\..*/;
  6.     //PRIMER Y FUNDAMETAL ERROR EN LOS NOMBRES: sendfrom o sendform ???
  7.     if (checked)
  8.     {
  9.         if (document.forms['sendform'].elements['vname'].value=="")
  10.         {
  11.             document.forms['sendform'].elements['vname'].focus();
  12.             document.forms['sendform'].elements['vname'].select();
  13.             alert ("Si us plau, ompli tots els camps.");
  14.             checked=false;
  15.         }
  16.     }
  17.     if (checked)
  18.     {
  19.         if (document.forms['sendform'].elements['nname'].value=="")
  20.         {
  21.             document.forms['sendform'].elements['nname'].focus();
  22.             document.forms['sendform'].elements['nname'].select();
  23.             alert ("Si us plau, ompli tots els camps.");
  24.             checked=false;
  25.         }
  26.     }
  27.     if (checked)                      
  28.     {
  29.         if ((pattern.test(document.forms['sendform'].elements['email'].value))==false)
  30.         {
  31.             document.forms['sendform'].elements['email'].focus();
  32.             document.forms['sendform'].elements['email'].select();
  33.             alert ("Si us plau, introduïu una adreça correcta de correu electrònic.");
  34.             checked=false;
  35.         }
  36.     }
  37.     if (checked)
  38.     {
  39.         if (document.forms['sendform'].elements['email'].value=="")
  40.         {
  41.             document.forms['sendform'].elements['email'].focus();
  42.             document.forms['sendform'].elements['email'].select();
  43.             alert ("Si us plau, ompli tots els camps.");
  44.             checked=false;
  45.         }
  46.     }
  47.    
  48.     if (checked)            
  49.     {
  50.         //ERROR nmbres: nachricht2 o nachricht???
  51.         if (document.forms['sendform'].elements['nachricht2'].value=="")
  52.         {
  53.             document.forms['sendform'].elements['nachricht2'].focus();
  54.             document.forms['sendform'].elements['nachricht2'].select();
  55.             alert ("Si us plau, ompli tots els camps.");
  56.             checked=false;
  57.         }
  58.     }
  59.     //NO hace Falta
  60.     //if (checked)
  61.     //{
  62.         //document.forms['sendform'].method="POST";
  63.         //document.forms['sendform'].action="w2dfgw.php";
  64.         //document.forms['sendform'].submit;
  65.     //}
  66.     return checked;
  67. }
  68. </script>
  69.      
  70.       <form name="sendform" onSubmit="return check();" method="post" action="w2dfgw.php" enctype="application/x-www-form-urlencoded">
  71.         <table border="0" cellpadding="0" cellspacing="0" width="310">
  72.           <input type="hidden" name="fgwemail" value="[email protected]">
  73.          
  74.           <input type="hidden" name="fgwsubject" value="Formulari B2T">
  75.          
  76.           <input type="hidden" name="fgwreturnurl" value="0000009d890112f04.html">
  77.          
  78.           <tr>
  79.             <td width="72" valign="top"><span class="grey">Nom</span></td>
  80.             <td width="239" valign="top"><input class="normal" style="width: 200px;" size="26" type="text" name="vname" value=""><br></td>
  81.             </tr>
  82.          
  83.           <tr>
  84.             <td valign="top"><span class="grey">Cognom</span></td>
  85.             <td valign="top"><input class="normal" style="width: 200px;" size="26" type="text" name="nname" value=""><br></td>
  86.           </tr>
  87.          
  88.           <tr>
  89.             <td valign="top"><span class="grey">E-Mail</span></td>
  90.             <td valign="top"><input class="normal" style="width: 200px;" size="26" type="text" name="email" value=""><br></td>
  91.           </tr>
  92.          
  93.           <tr>
  94.             <td valign="top"><span class="grey">Missatge</span></td>
  95.             <td valign="top"><textarea style="width: 200px;" cols="39" rows="7" class="normal" name="nachricht2"></textarea><br></td>
  96.           </tr>
  97.           <tr>
  98.             <td>&nbsp;</td>
  99.             <td>
  100.               <br>
  101.               </td>
  102.             </tr>
  103.          
  104.           <tr>
  105.             <td>&nbsp;</td>
  106.             <!-- Como esperas que el form se envie si no hay un input tipo submit ?????, con esto se resuelve: -->
  107.             <td align="left"><input onclick="document.forms['sendform'].submit();" type="image" border="0" src="../images/w2dsbmt.gif" usemap="0"></td>
  108.             </tr>
  109.           </table>
  110.          </form>