Posted By

ryarwood on 07/21/11


Tagged

javascript error forms validation checking


Versions (?)

Dead Simple Javascript Error Checking


 / Published in: JavaScript
 

  1. function quickSubmit() {
  2. errors = "";
  3. // the nasty error string
  4.  
  5. if (document.contactus.firstName.value == "") {
  6. errors += "First Name\n";
  7. //alert(errors);
  8. }
  9.  
  10. if (document.contactus.lastName.value == "") {
  11. errors+= "Last Name\n";
  12. }
  13. if (document.contactus.address1.value == "") {
  14. errors+= "Address\n";
  15. }
  16. if (document.contactus.city.value == "") {
  17. errors+= "City\n";
  18. }
  19. if (document.contactus.state.value == "") {
  20. errors+= "State\n";
  21. }
  22. if (document.contactus.zip.value == "") {
  23. errors+= "Zip\n";
  24. }
  25. if (document.contactus.phone.value == "") {
  26. errors+= "Phone\n";
  27. }
  28. if (document.contactus.email.value == "") {
  29. errors+= "Email\n";
  30. }
  31. if (errors == "") {
  32. document.contactus.submit();
  33. } else {
  34. alert("Please fill in the following fields:\n" + errors);
  35. }
  36.  
  37. }

Report this snippet  

You need to login to post a comment.