title: select/deselect all check boxes on click a single check box by javascript
body: <p>I have a form in which I have two table with some rows .
  <img src="https://i.stack.imgur.com/Zaghb.png" alt="enter image description here"></p>
  
  <p>I want that when I click on <em>select/unselect all</em> check box than checkboxes under the that check box should checked for that particular table </p>
  
  <p>I have a javascript function that works but when I click any of two <em>select/unselect all checkbox</em> than both tables checkboxes are checked.
  I want to check all checkboxes for the particular table only.</p>
  
  <p>Javascript:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  checked=false;
  function checkedAll (frm1) {
      var aa= document.getElementById('frm1');
       if (checked == false)
            {
             checked = true
            }
          else
            {
            checked = false
            }
      for (var i =0; i &lt; aa.elements.length; i++) 
      {
       aa.elements[i].checked = checked;
      }
        }
  
        //function for subscription month
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p>my html is....</p>
  
  <pre><code>&lt;form action="" method="post" name="frm1" id="frm1"&gt;
  
  &lt;table&gt;
  &lt;tr&gt;&lt;th&gt;Cause List&lt;/th&gt;&lt;/tr&gt;
  &lt;?php 
  foreach($arr as $month)
  {
  ?&gt;
  &lt;tr&gt;&lt;td&gt;&lt;input type="checkbox" name="causelist_month" /&gt;&lt;?php echo $month; ?&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;?php } ?&gt;
  &lt;tr&gt;&lt;th&gt;&lt;input type="checkbox" name="causelist_month" id="causelist_month" onclick="checkedAll (frm1);"/&gt;select all/unselect all&lt;/th&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;table&gt;
  &lt;tr&gt;&lt;th&gt;Subscription&lt;/th&gt;&lt;/tr&gt;
  &lt;?php 
  foreach($arr as $month)
  {
  ?&gt;
  &lt;tr&gt;&lt;td&gt;&lt;input type="checkbox" name="subscription_month"/&gt;&lt;?php echo $month; ?&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;?php } ?&gt;
  &lt;tr&gt;&lt;th&gt;&lt;input type="checkbox" name="subscription_month" id="subscription_month" onclick="checkedAll2 (frm2);"/&gt;select all/unselect all&lt;/th&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>please help me.</p>