Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. function validateForm()
  2. {
  3. //*snipped firstname, surname, email validation*
  4. var dob = document.getElementById("dateofbirth").value;
  5. // *snipped dob validation*
  6. var area = document.getElementById("areaofinterest").value;
  7. if (area == "")
  8. {
  9. alert("Please select an Area of Interest!");
  10. return false;
  11. }
  12.  
  13. var now = new Date();
  14. var birthdate = dob.split("/");
  15. var born = new Date(birthdate[2], birthdate[0]-1, birthdate[1]);
  16. age=get_age(born,now);
  17. if (area == "adults" && age<18)
  18. {
  19. alert("You need to be 18 years of age and older for the Adults books!");
  20. return false;
  21. }
  22.  
  23. }
  24.  
  25. function get_age(born, now) {
  26. var birthday = new Date(now.getFullYear(), born.getMonth(), born.getDate());
  27. if (now >= birthday)
  28. return now.getFullYear() - born.getFullYear();
  29. else
  30. return now.getFullYear() - born.getFullYear() - 1;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement