title: Passing a variable from a function to an if statement
body: <p>I have a submit button on a form for which I assigned a function to check required and visible fields. Upon encountering an empty field its supposed to add a class to a field, as well as display and error message. I have this jquery script:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(".submitBtn").click(function(validateAll) {
    if (validated = false) {
      alert("!!!");
      displayValidationErr();
    } else {
      $('#questionBody').submit();
    }
  });
  
  function validateAll() {
    var validated = true;
    $('.form-control').filter('[required]:visible').each(function() {
      if ($(this).val() === '') {
        $(this).addClass("emptyRequired");
        validated = false;
      }
    });
  }
  
  function displayValidationErr() {
    $("#validationError").fadeTo(2000, 600).slideUp(600, function() {
      $("#validationError").slideUp(600);
    });
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I am unable to pass a variable from "validateAll" function further upon clicking a button. Function works fine by itself, but not with if\else. 
  I am very new to this stuff, so please be easy on me. :)</p>
  
  <p>Thank you!</p>