title: Get value of checkbox by name
body: <p>I need to get the value of a checkbox by name.  I have the following code:</p>
  
  <pre><code>&lt;input type="hidden" name="my_checkbox" value="0"&gt;
  &lt;input type="checkbox" name="my_checkbox" id="my_checkbox_id" value="1"  /&gt;
  </code></pre>
  
  <p>The idea is that if the checkbox is not checked, I would get the value of the input type hidden (which is 0).  </p>
  
  <p>Here is what I have tried but did not work:</p>
  
  <pre><code>$('input[name=my_checkbox]').val();
  </code></pre>
  
  <p>However this returned the value of both the hidden input and checkbox.  Can anyone tell me how I can get the value of the checkbox when checked (1) or else get the value of the hidden input (0) when unchecked?  I guess this has to be done by name so that if the checkbox is unchecked, I get the value of the hidden input as if the checkbox is unchecked you won't get its value.</p>