title: Count the number of checked checkboxes in HTML
body: <p>So basically i want to count the number of checkboxes that are ticked. I get my code to the point where it counts them successfully, but I want to put in an alert that shows the number of checkboxes ticked, the code does this but doesn't show the total count, it increments the total every refresh. I just want to know how I can show a total count. </p>
  
  <p>It should display the total when the radio button 'yes' is clicked. </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;br /&gt;Apples
  &lt;input type="checkbox" name="fruit" /&gt;Oranges
  &lt;input type="checkbox" name="fruit" /&gt;Mango
  &lt;input type="checkbox" name="fruit" /&gt;
  &lt;br /&gt;Yes
  &lt;input type="radio" name="yesorno" id="yes" onchange="checkboxes()"
  </code></pre>
  
  <pre class="lang-js prettyprint-override"><code>function checkboxes(){
      var inputElems = document.getElementsByTagName("input"),
      count = 0;
      for (var i=0; i&lt;inputElems.length; i++) {
      if (inputElems[i].type === "checkbox" &amp;&amp; inputElems[i].checked === true){
          count++;
          alert(count);
      }
  }}
  </code></pre>