title: Javascript document.getElementById function not returning checkbox value to HTML form
body: <p>I have been searching for an answer everywhere but just can not find what I need.</p>
  <p>I have a webpage that has an HTML table on the left column and an HTML form on the right column. When I click on a row in the table on the left I want it to display the values in the form on the right.</p>
  <p>I have this working perfectly for the text fields on the form, but not for the two checkboxes. My javascript will return either true or false or checked and unchecked to the <code>document.getElementById</code> within the script itself by using <code>alert();</code> but I have no idea what it needs to allow the checkboxes to display these values. I thought the <code>document.getElementById </code>would return the values but it seems it does not.</p>
  <p>I have tried all kinds of conveluted ways to get this to work but can not seem to get the correct code needed.</p>
  <p>I am new to all this so there is most likely something really simple I am missing.</p>
  <p>This is the HTML form code:</p>
  <pre><code>&lt;div class=&quot;column right&quot;&gt;
    &lt;table&gt;
      &lt;tr&gt;&lt;/tr&gt;
      &lt;tr&gt;
        &lt;div class=&quot;lockinv&quot;&gt;
          &lt;form autocomplete=&quot;off&quot; name=&quot;lockform&quot; class=&quot;keyassign&quot; action=&quot;includes/lockinventory.inc.php&quot;
            method=&quot;post&quot;&gt;
            &lt;label id=&quot;inventory&quot; for=&quot;locknum&quot;&gt;Lock Number&lt;/label&gt;
            &lt;input id=&quot;invlocknum&quot; type=&quot;text&quot; name=&quot;locknum&quot; value=&quot;&quot; required&gt;
            &lt;label id=&quot;inventory&quot; for=&quot;locktype&quot;&gt;Lock Type&lt;/label&gt;
            &lt;input id=&quot;invlocktype&quot; type=&quot;text&quot; name=&quot;locktype&quot; value=&quot;&quot; required&gt;
            &lt;label id=&quot;inventory&quot; for=&quot;keycode&quot;&gt;Key Code&lt;/label&gt;
            &lt;input id=&quot;invkeycode&quot; type=&quot;text&quot; name=&quot;keycode&quot; value=&quot;&quot; required&gt;
  
            &lt;label id=&quot;inventory&quot; for=&quot;lockengraved&quot;&gt;Lock Engraved&lt;/label&gt;
            &lt;input id=&quot;invlockengraved&quot; type=&quot;hidden&quot; name=&quot;lockengraved&quot; value=&quot;0&quot;&gt;
            &lt;input id=&quot;invlockengraved&quot; type=&quot;checkbox&quot; name=&quot;lockengraved&quot; value=&quot;1&quot;&gt;
  
            &lt;label id=&quot;inventory&quot; for=&quot;lockmastered&quot;&gt;Lock Mastered&lt;/label&gt;
            &lt;input id=&quot;invlockmastered&quot; type=&quot;hidden&quot; name=&quot;lockmastered&quot; value=&quot;0&quot;&gt;
            &lt;input id=&quot;invlockmastered&quot; type=&quot;checkbox&quot; name=&quot;lockmastered&quot; value=&quot;1&quot;&gt;
  
            &lt;label id=&quot;inventory&quot; for=&quot;locknote&quot;&gt;Lock Note&lt;/label&gt;
            &lt;textarea id=&quot;inventorynote&quot; name=&quot;locknote&quot; rows=&quot;5&quot; cols=&quot;60&quot;&gt;&lt;/textarea&gt;
  
            &lt;div class=&quot;wheel&quot;&gt;
              &lt;?php
                if (isset($_GET[&quot;error&quot;])) {
                    if($_GET[&quot;error&quot;] == &quot;lockexists&quot;) {
                        echo &quot;&lt;p&gt;Lock Already In Inventory!&lt;/p&gt;&quot;;
                    }
                    else if ($_GET[&quot;error&quot;] == &quot;lockexistsfailed&quot;) {
                        echo &quot;&lt;p&gt;Lock Already In Inventory!&lt;/p&gt;&quot;;
                    }
                }
              ?&gt;
            &lt;/div&gt;
  
            &lt;input id=&quot;bt6&quot; type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Save&quot;&gt;
            &lt;button id=&quot;bt6&quot; type=&quot;reset&quot; name=&quot;button&quot;&gt;Cancel&lt;/button&gt;
          &lt;/form&gt;
        &lt;/div&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  <p>This is my JavaScript code:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
  
  &lt;script language=&quot;javascript&quot;&gt;&lt;/script&gt;
  
  &lt;script&gt;
    $(function () {
      $('#lockTable td').click(function () {
  
        var currentRow = $(this).closest(&quot;tr&quot;);
        var locknum = currentRow.find(&quot;td:eq(0)&quot;).text();
        var locktype = currentRow.find(&quot;td:eq(1)&quot;).text();
        var keycode = currentRow.find(&quot;td:eq(2)&quot;).text();
        var engraved = currentRow.find(&quot;td:eq(3)&quot;).find(&quot;:checkbox&quot;);
        var mastered = currentRow.find(&quot;td:eq(4)&quot;).find(&quot;:checkbox&quot;);
        var locknote = currentRow.find(&quot;td:eq(5)&quot;).text();
  
        var lockengraved = engraved.prop(&quot;checked&quot;);
        if (lockengraved === true) {
          $grved = &quot;checked&quot;;
        } else {
          $grved = &quot;unchecked&quot;;
        }
  
        var lockmastered = mastered.prop(&quot;checked&quot;);
        if (lockmastered === true) {
          $msted = &quot;checked&quot;;
        } else {
          $msted = &quot;unchecked&quot;;
        }
  
        document.getElementById('invlocknum').value = locknum;
        document.getElementById('invlocktype').value = locktype;
        document.getElementById('invkeycode').value = keycode;
        document.getElementById(&quot;invlockengraved&quot;).value = $grved;
        document.getElementById('invlockmastered').value = $msted;
        document.getElementById('inventorynote').value = locknote;
  
        alert(document.getElementById(&quot;invlockengraved&quot;).value);
        alert(document.getElementById(&quot;invlockmastered&quot;).value);
  
      });
    });
  &lt;/script&gt;
  </code></pre>
  <pre><code>&lt;p id=&quot;invlocknum&quot;&gt;&lt;/p&gt;
  &lt;p id=&quot;invlocktype&quot;&gt;&lt;/p&gt;
  &lt;p id=&quot;invkeycode&quot;&gt;&lt;/p&gt;
  &lt;p id=&quot;invlockengraved&quot;&gt;&lt;/p&gt;
  &lt;p id=&quot;invlockmastered&quot;&gt;&lt;/p&gt;
  &lt;p id=&quot;invlocknote&quot;&gt;&lt;/p&gt;
      
  &lt;p id=&quot;info&quot;&gt;&lt;/p&gt;
  &lt;p id=&quot;result&quot;&gt;&lt;/p&gt;
  </code></pre>