title: Handling OnCheckedChanged Checkbox Event with Javascript
body: <p>I have the following javascript function that I want to call on the check or uncheck of a checkbox:</p>
  
  <pre><code>    &lt;script language="javascript" type="text/javascript"&gt;
      function showHideDropDowns() {
          var check = document.getElementById('&lt;%= cbShowHideDDLs %&gt;')
          if (check.checked) {
              document.getElementById('&lt;%=ddlVendor%&gt;').style.visibility = 'visible';
              document.getElementById('&lt;%=ddlItem%&gt;').style.visibility = 'visible';
              document.getElementById('&lt;%=ddlorigin%&gt;').style.visibility = 'visible';
  
              document.getElementById('&lt;%=tbVendor%&gt;').style.visibility = 'hidden';
              document.getElementById('&lt;%=tbItems%&gt;').style.visibility = 'hidden';
              document.getElementById('&lt;%=tbOrigin%&gt;').style.visibility = 'hidden';
  
          }
          else {
              document.getElementById('&lt;%=ddlVendor%&gt;').style.visibility = 'hidden';
              document.getElementById('&lt;%=ddlItem%&gt;').style.visibility = 'hidden';
              document.getElementById('&lt;%=ddlorigin%&gt;').style.visibility = 'hidden';
  
              document.getElementById('&lt;%=tbVendor%&gt;').style.visibility = 'visible';
              document.getElementById('&lt;%=tbItems%&gt;').style.visibility = 'visible';
              document.getElementById('&lt;%=tbOrigin%&gt;').style.visibility = 'visible';
          }
      }
      &lt;/script&gt;
  </code></pre>
  
  <p>Trying to add and attribute using OnCheckedChanged or OnClick has not worked:</p>
  
  <pre><code>    &lt;asp:CheckBox ID="cbShowHideDDLs" runat="server" Text="Show Lists"  /&gt;
  
  
      protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
              {
                  cbShowHideDDLs.Attributes.Add("onclick", "showHideDropDowns();");
                  //cbShowHideDDLs.Attributes.Add("OnCheckedChanged","showHideDropDowns();");
              }
      }
  </code></pre>