We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

damarev on 10/06/06


Tagged


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

luman


validaFormulario(obj)


Published in: JavaScript 


  1. function validaFormulario(obj){
  2. //obj = document.forms[0];
  3. var errores = new Array();
  4. with (obj){
  5.  
  6. if(nombre.value==""){
  7. errores.push("- El campo "<strong>Nombre</strong>" es obligatorio.");
  8. }
  9.  
  10. if(apellidos.value==""){
  11. errores.push("- El campo "<strong>Apellidos</strong>" es obligatorio.");
  12. }
  13.  
  14. if(cod_postal.value==""){
  15. errores.push("- El campo "<strong>Código Postal</strong>" es obligatorio.");
  16. }
  17.  
  18. if(sexo[0].checked==false && sexo[1].checked==false){
  19. errores.push("- El campo "<strong>Sexo</strong>" es obligatorio.");
  20. }
  21.  
  22. e=email.value;
  23. if( (e=="") || (e.indexOf("@")==-1 || e.indexOf(".")==-1) ){
  24. errores.push("- El campo "<strong>Email</strong>" es obligatorio.");
  25. }
  26.  
  27. if(condiciones.checked==false){
  28. errores.push("- Si desea registrarse, por favor acepte las <strong>condiciones de uso</strong> marcando la casilla correspondiente.");
  29. }
  30.  
  31. }
  32.  
  33. if (errores.length > 0){
  34. var mensajes = "Por favor, corriga los siguientes errores:<br><br>";
  35. for(var i=0; i<errores.length; i++){mensajes += errores[i]+"<br>";}
  36. var errores = document.getElementById("errores");
  37. errores.innerHTML = mensajes;
  38. errores.style.display = "block";
  39. document.location.href = "#errores";
  40. //alert(mensajes);
  41. return false;
  42. }else{
  43. var errores = document.getElementById("errores");
  44. errores.innerHTML = "";
  45. errores.style.display = "none";
  46. }
  47. }

Report this snippet 

You need to login to post a comment.