title: Javascript form validation, too many if statements?
body: <p>I have a form with five elements, <code>firstName</code>, <code>lastName</code>, <code>username</code>, <code>password</code> and <code>passwordConfirmation</code></p>
  
  <pre><code>var errors = [];
  var errorsText = [];
  
  
  function generateError(messageText, elementIdentifier) {
  var messageText = messageText;
  var elementIdentifier = elementIdentifier;
  errors.push(elementIdentifier);
  errorsText.push(messageText);
  return false;
  }
  
  
  
  function validateRegistrationForm(firstName, lastName, username, password, passwordConfirmation) {
  formReset();
  //alert("validateRegistrationForm() has been called");
  
  var firstName = firstName;
  //alert("First Name = \'" + firstName + "\'");
  var lastName = lastName;
  //alert("Last Name = \'" + lastName + "\'");
  var username = username;
  //alert("Username = \'" + username + "\'");
  var password = password;
  //alert("Password = \'" + password + "\'");
  var passwordConfirmation = passwordConfirmation;
  //alert("Password Confirmation = \'" + passwordConfirmation + "\'");
  
  if ( ( firstName == null ) || ( firstName == "" ) ) {
      //alert("//firstname hasn't been filled out");
  
      generateError("You must provide a First Name", "firstName");
  } 
  
  if ( ( lastName == null ) || ( lastName == "" ) ) {
      //lastname hasn't been filled out
      generateError("You must provide a Last Name", "lastName");
  }
  
  if ( ( username == null ) || ( username == "" ) ) {
      //username hasn't been filled out
      generateError("You must enter a Username", "username");
  }
  
  if ( ( password == null ) || ( password == "" ) ) {
      //password hasn't been filled out
      generateError("You haven\'t entered a password", "password");
  }
  
  if ( ( passwordConfirmation == null ) || ( passwordConfirmation == "" ) ) {
      //passwordconfirmation hasn't been filled out
      generateError("You haven\'t confirmed your password", "passwordConfirmation");
  }
  
  validatePassword(password, passwordConfirmation);
  
  }
  </code></pre>
  
  <p>Is there a better way to handle all of the <code>if statements</code>?</p>