Ver Mensaje Individual
  #2 (permalink)  
Antiguo 28/03/2012, 17:21
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: validar campos vacios, continua de pagina

Sin entrar a analizar detalles de la validación, que no es correcta (podrían pasarte espacios en blanco en los campos y validaría correctamente, consultá como hacer trim() con javascript). El método que estás usando para llamar la función, no es el indicado
Lee
http://www.forosdelweb.com/f13/docum...0/#post4151210

tendrías que tener algo como esto
Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <title>titulo</title>
  4. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  5.  
  6.  
  7. function comprobar(){
  8.     var mal=false;
  9.    
  10.     numero=document.forms[0].elements.length;
  11.    
  12.     for(a=0;a<numero;a++){
  13.        if (document.forms[0].elements[a].value==""){
  14.            document.forms[0].elements[a].style.backgroundColor="#ffffcc";
  15.            mal=true;
  16.        }
  17.        else{
  18.            document.forms[0].elements[a].style.backgroundColor="white";
  19.        }
  20.    }
  21.    
  22.    if(mal){
  23.        alert("Por favor, rellene las cajas coloreadas");
  24.        return false;
  25.    }
  26.        else{document.forms[0].submit()}
  27.    }
  28.  
  29. </head>
  30.  
  31.  
  32.  
  33.  
  34.  
  35. <form action="ingresar1.php" method="post" onsubmit="return comprobar();" >
  36.   <p>&nbsp;</p>
  37.   <table width="330" border="0" cellspacing="3" cellpadding="3">
  38.     <tr>
  39.       <th width="94" scope="col">&nbsp;</th>
  40.       <th width="223" scope="col">&nbsp;</th>
  41.     </tr>
  42.     <tr>
  43.       <td>Nick:</td>
  44.       <td><input type="text" name="textnick"></td>
  45.     </tr>
  46.     <tr>
  47.       <td>Clave:</td>
  48.       <td><input type="text" name="txtclave1"></td>
  49.     </tr>
  50.     <tr>
  51.       <td>Repetir clave :</td>
  52.       <td><input type="text" name="txtclave2"></td>
  53.     </tr>
  54.     <tr>
  55.       <td>Nivel:</td>
  56.       <td><select name="select">
  57.         <option value="1">Basico</option>
  58.         <option value="2">Admin</option>
  59.       </select></td>
  60.     </tr>
  61.     <tr>
  62.       <td>&nbsp;</td>
  63.       <td><input type="submit" name="Submit" value="Ingresar"></td>
  64.     </tr>
  65.   </table>
  66.   <p>&nbsp;</p>
  67. </form>
  68.  
  69.  
  70. </body>
  71. </html>

Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.