title: Get only checked element from getElementsByName() in Javascript?
body: <p>I have a HTML like this:</p>
  
  <pre><code>&lt;input type="checkbox" name="choice_shrd_with_me" id="choice{{ forloop.counter }}" value="{{ choice.file_name }}" /&gt;
  </code></pre>
  
  <p>I am trying to get only the checked elements in array like this in Javascript:</p>
  
  <pre><code>var choices = [];
           for (var i=0;i&lt;document.getElementsByName('choice_shrd_with_me').length;i++){
               choices.push(document.getElementsByName("choice_shrd_with_me")[i].value);
           }
  </code></pre>
  
  <p>The above gets all the values whether the checkbox is checked or not. I want to get only the values on which checkbox is checked. How can I do that?</p>