title: Select all checkboxes JS toggle issue
body: <p>Hoping someone can help me overcome my Javascript ignorance.</p>
  
  <p>I've got a form that includes checkboxes and I've got a piece of JS that toggles selecting/deselecting all the boxes.  And so far, it all works as expected.</p>
  
  <p>The wrench in the works is that I've got multiple groups of checkboxes in this form and I would like to select/deselect by group, not all the checkboxes in the form.  This is a sample of the php and html.  As you can see, the form is in a table and there is a checkbox in the header row that performs the action. 'resources_req' is the name of the checkbox element in the form</p>
  
  <pre><code>&lt;form method="post" name="add_reservation"&gt; 
  &lt;?php for($x=0; $x&lt;count($groups); $x++) : // make seperate display for each group ?&gt;
      &lt;div class="group_&lt;?php echo $group_label; ?&gt;"&gt;
      &lt;table class="res"&gt;
          &lt;tr&gt;
  &lt;!-- form: checkbox all --&gt;
      &lt;?php if($make_res == 'enter') : // adds checkbox to check all ?&gt;
              &lt;th&gt;&lt;input type="checkbox"  onClick="toggle(this, 'resources_req[]')" /&gt;&lt;/th&gt;
      &lt;?php endif; ?&gt;
  &lt;!-- end form: checkbox all --&gt;
          &lt;/tr&gt;
  ...
  foreach($resources as $resource) { // for each resource/laptop
      $form_start = '&lt;td&gt;';
          $form_start .= '&lt;input type="checkbox" name="resources_req[]" value="'.$resource['id'].'"';
          $form_start .= ' /&gt;';
      $form_start .= '&lt;/td&gt;';
  }
  ...
      &lt;/table&gt;
      &lt;/div&gt;
  &lt;?php endfor; // loop for each group ?&gt;
  &lt;input type="submit" name="add_reservation" value="Make this reservation"  /&gt;
  &lt;/form&gt; 
  </code></pre>
  
  <p>Here is the JS being called:</p>
  
  <pre><code>function toggle(source, element) {
      checkboxes = document.getElementsByName(element);
      for(var i in checkboxes)
          checkboxes[i].checked = source.checked;
  }
  </code></pre>
  
  <p>Best I can put together, the 'this' in the script call is referring to the form.  I thought if maybe I put each of these groups in to their own div class, I could then somehow refer to just that but now I'm just lost.  Any help or suggestions appreciated!</p>
  
  <p>EDIT: I asked for suggestions and it's been suggested I post only the html:</p>
  
  <pre><code>&lt;form method="post" name="add_reservation"&gt; 
      &lt;div class="group_A"&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;th&gt;&lt;input type="checkbox"  onClick="toggle(this, 'resources_req[]')" /&gt;&lt;/th&gt;
                  &lt;th&gt;Name&lt;/th&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;input type="checkbox" name="resources_req[]" value="1" /&gt;&lt;/td&gt;
                  &lt;td&gt;John&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;input type="checkbox" name="resources_req[]" value="2" /&gt;&lt;/td&gt;
                  &lt;td&gt;Bill&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;input type="checkbox" name="resources_req[]" value="3" /&gt;&lt;/td&gt;
                  &lt;td&gt;Fred&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/div&gt;
      &lt;div class="group_b"&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;th&gt;&lt;input type="checkbox"  onClick="toggle(this, 'resources_req[]')" /&gt;&lt;/th&gt;
                  &lt;th&gt;Name&lt;/th&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;input type="checkbox" name="resources_req[]" value="4" /&gt;&lt;/td&gt;
                  &lt;td&gt;George&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;input type="checkbox" name="resources_req[]" value="5" /&gt;&lt;/td&gt;
                  &lt;td&gt;Tom&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;input type="checkbox" name="resources_req[]" value="6" /&gt;&lt;/td&gt;
                  &lt;td&gt;Raymons&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/div&gt;
      &lt;input type="submit" name="add_reservation" value="Make this reservation"  /&gt;
  &lt;/form&gt; 
  </code></pre>