title: javascript - how to automatically check checkbox when adding value to textbox
body: <p>I know a little about javascript in ASP.NET. I put textbox next to checkbox control. So when you type in a textbox, checkbox should automatically get checked. And when you erase string in textbox, the checkbox should automatically get unchecked. How to code in javascript?</p>
  
  <p>What I am trying to code here is not working:</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
      function TextboxFunction() {
          if (document.getElementById("txtQuestion").textContent != null)
              document.getElementById("cbxYes").checked = true;
  
          if (document.getElementById("txtQuestion").textContent == null)
              document.getElementById("cbxYes").checked = false;
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>Asp.net (listview)</p>
  
  <pre><code>&lt;ItemTemplate&gt;
      &lt;tr class="item" runat="server"&gt;
          &lt;td&gt;&lt;asp:TextBox ID="txtQuestion" OnChange="javascript:TextboxFunction();" AutoPostBack="true" Width="200px" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;
          &lt;td&gt;&lt;asp:CheckBox ID="cbxYes" runat="server"  AutoPostBack="True" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/ItemTemplate&gt;
  </code></pre>