ok ya me funciono pero con evento onclick y no con el evento onsumbit, tengo esto:
Código HTML:
Ver original<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript"> function validar(valor){
if(document.contact.campo.value.length==0){
document.getElementById('nombre').style.display="inline"
document.contact.campo.focus()
return false;
} else {
document.getElementById('nombre').style.display="none"
}
if(document.contact.campo2.value.length==0){
document.getElementById('apellido').style.display="inline"
document.contact.campo2.focus()
return false;
} else {
document.getElementById('apellido').style.display="none"
}
if(document.contact.email.value.length==0){
document.getElementById('email').style.display="inline"
document.contact.email.focus()
return false;
} else {
document.getElementById('email').style.display="none"
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
} else {
document.getElementById('email2').style.display="inline"
document.contact.email.focus()
return false;
}
}
}
<form name="contact" action="index.php" method="post"> nombre:
<input type="text" name="campo" /> <b id="nombre" style="display:none; color:#ff0000;">Ingrese Nombre
</b>apellido:
<input type="text" name="campo2" /> <b id="apellido" style="display:none; color:#ff0000;">Ingrese Apellido
</b>email:
<input type="text" name="email" /> <b id="email" style="display:none; color:#ff0000;">Ingrese Email
</b><b id="email2" style="display:none; color:#ff0000;">Email en formato no valido
</b><input type="submit" value="submit" onclick="return validar(this.form.email.value);" />
pero porque con onclick y no con onsubmit si deberia de funcionar con onsubmit, ya que es la regla de validacion para formulario??