Ver Mensaje Individual
  #3 (permalink)  
Antiguo 01/12/2007, 09:31
Avatar de hgp147
hgp147
 
Fecha de Ingreso: diciembre-2006
Ubicación: Buenos Aires, Argentina
Mensajes: 980
Antigüedad: 18 años, 2 meses
Puntos: 36
Re: Validar form con javascript

Hola JavierB, gracias por el código, era justo lo que quería. Pero tengo una duda: al intentar agregar otro campo de texto, solamente me valida el primero y el otro no. Aca dejo el código:

Código HTML:
<html>
<head>
<script type="text/javascript">
function validar(frm) {
  
  if (frm.pepe.value.length < 4) {
   document.getElementById('error').style.visibility = 'visible';
   return false;
   } 
   
   
   if (form.pepe2.value.length < 4) {
   document.getElementById('error2').style.visibility = 'visible';
   return false;
   } 
   
}
</script>
</head>
<body>
<form action="procesa.php" method="post" onsubmit="return validar(this)">

<input type="text" name="pepe" />
<p id="error" style="visibility:hidden">Longitud inválida</p>

<input type="text" name="pepe2" />
<p id="error2" style="visibility:hidden">Longitud inválida2</p>

<input type="submit" />
</form>
</body>
</html>