Errors coming up but then disapearing


#1


For some reason when I press the Create Account button only the errors for the first and last name pop up, and then the page refreshes and there are no error messages. Can someone help me get the error messages for the password and email to pop up, and how do I get my page to not refresh after I press Create Account. My code is down below:


var main = function() {
  $('form').submit(function() {
    var firstName = $('#first').val();
    
    if(firstName === "") {
      $('.first-name-error').text("Please enter your first name.");
    }
    var lastName = $('#last').val();
    
    if(lastName === ""){
      $('.last-name-error').text("PLease enter your last name.");
    }
    
    var email = $('email').val();
    
    if(email === ""){
      $('p.email-error').text("Please enter your email address.");
    }
    
    else if(email === "sasham@maximdim.com"){
      $('email-error').text('This email is already taken.');
    }
    
    
    var password = $('password').val();
    
    if(password ===""){
      $('password-error').text("Please enter a password.");
    }
    else if(password.length < 8){
      $('password-error').text("Short passwords are easy to guess. Try one with at least 8 characters.");
    }

    return false;
  });
};

$(document).ready(main);


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.