Ver Mensaje Individual
  #3 (permalink)  
Antiguo 07/06/2011, 22:29
jobu
 
Fecha de Ingreso: enero-2010
Mensajes: 63
Antigüedad: 14 años, 3 meses
Puntos: 5
Respuesta: Campos imprescindibles

este es un ejemplo sencillo para validar un formulario con javascript.

Código HTML:
Ver original
  1.   <head>
  2.   <title></title>
  3.  
  4.   <script language="javascript">
  5.  
  6.    function validar_campos()
  7.   {
  8.       if ((document.myform.name.value=="") || (document.myform.name.value==null))
  9.     {
  10.        document.myform.name.focus();
  11.        alert ("campo obligatorio...!!!");
  12.        return false;
  13.     }
  14.    return true;
  15.   }
  16.      
  17.     function enviar()
  18.       {
  19.        
  20.         if (validar_campos())
  21.         {
  22.            document.myform.submit();    
  23.         }
  24.       }
  25.    
  26.  
  27.   </head>
  28.   <body>
  29.  
  30.   <form name="myform" action="destino.php" method="POST">
  31.  
  32.   Nombre <input name="name" type="text" size=60 ><br>
  33.  
  34.    <input type="button" value="Enviar" onclick="enviar();">
  35.  
  36.   </form>
  37.  
  38.   </body>
  39. </html>