Advertisement
Guest User

Untitled

a guest
Mar 12th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. // REQUIRES JQUERY
  2.  
  3. // when the page is ready
  4. $(function() {
  5. // when the submit button is clicked
  6. $('#submit-button').on('click', function(e) {
  7. // clear out all the error messages
  8. $('.error-field').removeClass('error-field');
  9.  
  10. // grab the values of the text boxes
  11. var username = $('#username').val();
  12. var email = $('#email').val();
  13. var password = $('#password').val();
  14.  
  15. // starts off valid
  16. var valid = true;
  17.  
  18. // if username is blank, it's invalid and adds errors to the username label/field
  19. if(username === "" || username == null) {
  20. valid = false;
  21. $('#label-username').addClass('error-field');
  22. $('#username').addClass('error-field');
  23. }
  24.  
  25. // if email is blank, it's invalid and adds errors to the email label/field
  26. if(email === "" || email == null) {
  27. valid = false;
  28. $('#label-email').addClass('error-field');
  29. $('#email').addClass('error-field');
  30. }
  31.  
  32. // if password is blank, it's invalid and adds errors to the password label/field
  33. if(password === "" || password == null) {
  34. valid = false;
  35. $('#label-password').addClass('error-field');
  36. $('#password').addClass('error-field');
  37. }
  38.  
  39. // if returns true, will actually POST to the server. if false, won't POST
  40. return valid;
  41. });
  42. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement