Published in: JavaScript
function validaFormulario(obj){ //obj = document.forms[0]; var errores = new Array(); with (obj){ if(nombre.value==""){ errores.push("- El campo "<strong>Nombre</strong>" es obligatorio."); } if(apellidos.value==""){ errores.push("- El campo "<strong>Apellidos</strong>" es obligatorio."); } if(cod_postal.value==""){ errores.push("- El campo "<strong>Código Postal</strong>" es obligatorio."); } if(sexo[0].checked==false && sexo[1].checked==false){ errores.push("- El campo "<strong>Sexo</strong>" es obligatorio."); } e=email.value; if( (e=="") || (e.indexOf("@")==-1 || e.indexOf(".")==-1) ){ errores.push("- El campo "<strong>Email</strong>" es obligatorio."); } if(condiciones.checked==false){ errores.push("- Si desea registrarse, por favor acepte las <strong>condiciones de uso</strong> marcando la casilla correspondiente."); } } if (errores.length > 0){ var mensajes = "Por favor, corriga los siguientes errores:<br><br>"; for(var i=0; i<errores.length; i++){mensajes += errores[i]+"<br>";} var errores = document.getElementById("errores"); errores.innerHTML = mensajes; errores.style.display = "block"; document.location.href = "#errores"; //alert(mensajes); return false; }else{ var errores = document.getElementById("errores"); errores.innerHTML = ""; errores.style.display = "none"; } }
You need to login to post a comment.
