title: Unable to reassign global variable in JavaScript function
body: <p>I'm having problems reassigning the value of an object's property from inside a JavaScript/jQuery function.</p>
  <p>I'm writing some basic validation on six input fields within a form element, ensuring the fields are not empty. Once all input fields have a value in them, I'd like to display additional input fields in the form that are initially hidden.</p>
  <p>The problem I have is I can't update my object properties from within my function.</p>
  <p>I'm passing a variable in a function, and it seems to be updated within my function but I'm not seeing the variable's value change globally.</p>
  <p>Here's the object in the global scope that keeps track of whether the fields are validated:</p>
  <pre><code>var validationObject = {
    titleValid: &quot;n&quot;,
    firstNameValid: &quot;n&quot;,
    lastNameValid: &quot;n&quot;,
    emailValid: &quot;n&quot;,
    contactEmailValid: &quot;n&quot;,
    contactSMSValid: &quot;n&quot;
  }
  
  </code></pre>
  <p>For each field I'm calling a version of this function. I think the problem is here -- one of the arguments I'm passing in the function is 'firstNameValid':</p>
  <pre><code>function firstNameIsValid() {
    return fieldHasValue($(&quot;input#field_firstName&quot;), $(&quot;div#first_name_error&quot;), firstNameValid);
    }
    $(&quot;input#field_firstName&quot;).on('change blur', firstNameIsValid);
  </code></pre>
  <p>The preceding function uses this function, which I'm planning to reuse with all input fields:</p>
  <pre><code>function fieldHasValue(field, label, validationProperty) {
    var value = field.val().trim(); //Grab value without leading or trailing whitespace
    if (value.length &gt; 0) {
      label.hide(); //hide error message 
      validationProperty = &quot;y&quot;; //set property in global object?
    } else {
      label.show();
      validated = &quot;n&quot;;
      field.focus();
    }
    return (value.length &gt; 0);
  }
  
  </code></pre>
  <p>After running the function, the third parameter in the fieldHasValue function, 'validationProperty', is being used literally within the firstNameIsValid function. The result is my object becomes:</p>
  <pre><code>var validationObject = {
    titleValid: &quot;n&quot;,
    firstNameValid: &quot;n&quot;,
    lastNameValid: &quot;n&quot;,
    emailValid: &quot;n&quot;,
    contactEmailValid: &quot;n&quot;,
    contactSMSValid: &quot;n&quot;,
    validationProperty: &quot;y&quot;
  }
  
  </code></pre>
  <p>If you know how I can update the object from within the fieldHasValue() function, please send word.</p>