title: Trying to set hidden input's value to toggle between True and False in JavaScript
body: <p>I am attempting to toggle the value of hidden inputs between true and false by users clicking on table cells. I am able to successfully assign event handlers to the cells, and get their values. My toggling function (<code>true_switch</code>) appears to always return false, however, and I can't be sure if it actually switches the values.</p>
  
  <p>I would love it if someone could tell me what I am doing wrong? I had previously tried this using Boolean data-type variables, but I gave up on that because I wasn't sure how HTML value fields, and JavaScript's Boolean datatypes interact (I seemed to be getting false a lot, even when I expected true).</p>
  
  <p>JavaScript:    </p>
  
  <pre><code>var JS_elements = document.getElementsByClassName("JS")
  
  for (y = 0; y &lt; JS_elements.length; y++){
      x = JS_elements[y].getElementsByTagName("input")[0]
  
      JS_elements[y].addEventListener('click', function() {
          switch_JS(this);
      });
  }
  
  function true_switch(val) {
      document.getElementById("testblock").innerHTML +=  " ; true_switch worked "; &lt;!-- debug line --&gt;
      if (val = "true") {
          return "false"
      } else if (val = "false") {
          return "true"
      } else {
          alert("Error in the true_switch routine.")
      }
  }
  
  function switch_JS(domobj) {
      &lt;!-- takes as input an HTML object, and switched the value from true to false, or from false to true --&gt;
      val = domobj.getElementsByTagName("input")[0].value
      &lt;!-- alert(val); --&gt;
      document.getElementById("testblock").innerHTML = document.getElementById("testblock").innerHTML + " | Step 1 worked; "; &lt;!-- debug line --&gt;
      document.getElementById("testblock").innerHTML = document.getElementById("testblock").innerHTML +' ; val: ' + val + ' ; type: ' + typeof val + " ; true_switch(val): " + true_switch(val); &lt;!-- debug line --&gt;
      domobj.getElementsByTagName("input")[0].value = true_switch(val);
      document.getElementById("testblock").innerHTML = document.getElementById("testblock").innerHTML + " ; input value: " + domobj.getElementsByTagName("input")[0].value; &lt;!-- debug line --&gt;
  }
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;header&gt;
          &lt;hr&gt;
              &lt;p&gt;- Header Background Color Controller -&lt;/p&gt;
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Javascript Controller:&lt;/td&gt;
                      &lt;td class="JS"&gt;Red
                          &lt;input type="hidden" value="true"&gt;
                      &lt;/td&gt;
                      &lt;td class="JS"&gt;Green
                          &lt;input type="hidden" value="true"&gt;
                      &lt;/td&gt;
                      &lt;td class="JS"&gt;Blue
                          &lt;input type="hidden" value="true"&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;jQuery Controller:&lt;/td&gt;
                      &lt;td class="jQ" value=false&gt;Red&lt;/td&gt;
                      &lt;td class="jQ" value=false&gt;Green&lt;/td&gt;
                      &lt;td class="jQ" value=false&gt;Blue&lt;/td&gt;
                  &lt;tr&gt;
              &lt;/table&gt;
          &lt;hr&gt;
      &lt;/header&gt;
  </code></pre>