Advertisement
Guest User

Untitled

a guest
Jan 29th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 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.  
  43. // when the clear button is clicked
  44. $('#clear-button').on('click', function(e) {
  45. // prevent any default behavior (possibly submitting the form)
  46. e.preventDefault();
  47. // set the value of all input boxes to an empty string
  48. $('form#signin-form').find('input[type=text],input[type=email],input[type=password]').val('');
  49. // clear out all the error messages
  50. $('.error-field').removeClass('error-field');
  51. });
  52. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement