title: Display all selected checkboxes
body: <p>I'm trying to display all selected checkboxes from this form. </p>
  
  <pre><code>&lt;form name="myform"&gt;
          Select a check box: &lt;br&gt; &lt;br&gt;
          Check Box 0: &lt;input TYPE="checkbox" NAME="checkBox" checked&gt; &lt;br&gt;
          Check Box 1: &lt;input TYPE="checkbox" NAME="checkBox"&gt; &lt;br&gt;
          Check Box 2: &lt;input TYPE="checkbox" NAME="checkBox"&gt; &lt;br&gt;
          Check Box 3: &lt;input TYPE="checkbox" NAME="checkBox"&gt; &lt;br&gt; &lt;br&gt;
          &lt;input type="button" name="button" Value="Click Me" onClick="getCheckedBoxes(this.form)"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is JS code. I'm stuck here now and can't make it working. Thank you in advance.</p>
  
  <pre><code>function getCheckedBoxes(checkBox) {
        var checkboxes = document.getElementsByName(checkBox);
        var checkboxesChecked = [];
  
        for (var i=0; i&lt;checkboxes.length; i++) {
           if (checkboxes[i].checked) {
              checkboxesChecked.push(checkboxes[i]);
           }
        }
        return checkboxesChecked.length &gt; 0 ? checkboxesChecked : null;
      }
  
      var checkedBoxes = getCheckedBoxes("checkBox");
  
      alert ("Check box " + checkedBoxes + " is selected ");
  </code></pre>