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>