Guest User

Untitled

a guest
Feb 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. function validate(f){
  2.  
  3. var checked = new Array();
  4. var errors = new Array();
  5.  
  6. a = document.getElementsByTagName('input');
  7. for(i = 0; i < a.length; i++) {
  8. if(a[i].type == 'checkbox' && a[i].checked==true) {
  9. checked.push(a[i]);
  10. }
  11. }
  12.  
  13. if(checked.length == 0) {
  14. errors.push('You must select at least one service');
  15. }
  16. if(f.firstName.value == "") {
  17. errors.push("You forgot to enter your first name.");
  18. f.firstName.focus();
  19. }
  20. if (f.lastName.value == ""){
  21. errors.push("You forgot to enter your last name.");
  22. f.lastName.focus();
  23. }
  24. if(f.email.value == "") {
  25. errors.push("You forgot to enter your email address.");
  26. f.email.focus();
  27. }
  28. if(f.phone.value == "") {
  29. errors.push("You forgot to enter a phone number.");
  30. f.phone.focus();
  31. }
  32.  
  33. if(errors.length == 0) {
  34. return true;
  35. }
  36. else {
  37. document.getElementById("errors").innerHTML = errors.join("<br />")
  38. return false;
  39. }
  40. }
Add Comment
Please, Sign In to add comment