hola buento tgengo problemas con este codigo
Código:
<script type="text/javascript">
function validar(frm) {
var resultado1 = true;
var resultado2 = true;
if (frm.pepe.value.length < 4) {
document.getElementById('error').style.visibility = 'visible':'longitud invalida';
resultado1 = false; // Error
}
else {
document.getElementById('error').style.visibility = 'hidden';
resultado1 = true; // Sin error
}
if (frm.pepe2.value.length < 4) {
document.getElementById('error2').style.visibility = 'visible': 'Email invalido';
resultado2 = false; // Error
}
else {
document.getElementById('error2').style.visibility = 'hidden';
resultado3 = true; // Sin error
}
return(resultado1 && resultado2);
}
</script>
</head>
<body>
<form action="procesa.php" method="post" onsubmit="return validar(this)">
<input type="text" name="pepe" /><br>
<input type="text" name="pepe2" /><br>
<p id="error" style="visibility:hidden">Longitud inválida</p>
<p id="error2" style="visibility:hidden">Longitud inválida2</p>
<input type="submit" />
</form>
</body>
</html>
Como hago para cuando sea un solo error no muestre el espacio del otro en blanco si no que lo remplase un ejemplo es este pero esta en ajax [URL="http://www.desarrolloweb.com/articulos/ejemplos/ajax/xajax/recibir_validar_formulario_ajax_php.php"]http://www.desarrolloweb.com/articulos/ejemplos/ajax/xajax/recibir_validar_formulario_ajax_php.php[/URL] y lo nesesito en javascript