title: Check all / uncheck all Checkbox in looping statement
body: <p>i have a problem with my program. Here's my snippet code.</p>
  
  <p>Here's the Javascript/Jquery code.</p>
  
  <pre><code>&lt;script language='javascript'&gt;
  
  ///SELECTING CHECKBOXES////
  $(function(){
  
  // add multiple select / deselect functionality
  $("#selectall").click(function () {
        $('.case').attr('checked', this.checked);
  });
  
  // if all checkbox are selected, check the selectall checkbox
  // and viceversa
  $(".case").click(function(){
  
      if($(".case").length == $(".case:checked").length) {
          $("#selectall").attr("checked", "checked");
      } else {
          $("#selectall").removeAttr("checked");
      }
  
  });
  });
  &lt;/script&gt;
  </code></pre>
  
  <hr>
  
  <p>And here's the code where i will integrate that javascript.</p>
  
  <pre><code> &lt;h2&gt;Quotation ID&lt;/h2&gt;
              &lt;?php
  
          $select_orders = mysql_query ("SELECT * FROM tblorder WHERE project_id = '$project_id' GROUP BY quotation_id") OR DIE (mysql_error());
          while ($row2=mysql_fetch_array($select_orders)){
              $quote_id = $row2['quotation_id'];
  
  
              ?&gt;
          &lt;h3 class="expand"&gt;&lt;?php echo $quote_id; ?&gt;&lt;/h3&gt;
          &lt;div class="collapse"&gt;
              &lt;table align='center' border='1' class='display'&gt;
                  &lt;thead&gt;
                      &lt;th&gt;&lt;input type='checkbox' onclick='checkall()' id='selectall'/&gt;&lt;/th&gt;
                      &lt;th&gt;Product Type&lt;/th&gt;
                      &lt;th width='20px'&gt;Product type code&lt;/th&gt;
                      &lt;th width='20px'&gt;Quantity&lt;/th&gt;
                      &lt;th&gt;Width&lt;/th&gt;
                      &lt;th&gt;Height&lt;/th&gt;
                      &lt;th&gt;Total Sub.&lt;/th&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                  &lt;?php
                  $tots_tots = 0;
                  $tots_subs = 0;
                  $select_orders2 = mysql_query ("SELECT * FROM tblorder WHERE project_id = '$project_id' AND quotation_id = '$quote_id'") OR DIE (mysql_error());
                      while ($row3=mysql_fetch_array($select_orders2)){
                          $idd = $row3['id'];
                          $project_id2 = $row3['project_id'];
                          $order_id = $row3['quotation_id'];
                          $prod_type = $row3['prod_type'];
                          $prod_type_code = $row3['prod_type_code'];
                          $qty = $row3['qty'];
                          $width = $row3['width'];
                          $height = $row3['height'];
                          $tot_sub = $row3['total_subs'];
  
                          $tots_subs += $tot_sub;
  
                  echo "&lt;tr bgcolor='".$colors[$c++ % 2]."' align='center'&gt;";
                      echo "&lt;td&gt;
                      &lt;input type='hidden' name='project_name' value='$project_name'&gt;
                      &lt;input type='checkbox' name='check_ptc[]' value='$prod_type_code' style='display:none;' checked&gt;
                      &lt;input type='checkbox' class='case' name='checkbox[]' value='".$idd."'&gt;&lt;/td&gt;";
                      echo "
                              &lt;input type='hidden' name='project_id[]' value='$project_id2'&gt;
                          &lt;/td&gt;";
                      echo "&lt;td&gt;".$prod_type."
                              &lt;input type='hidden' name='quotation_id[]' value='$order_id'&gt;
                              &lt;input type='hidden' name='prod_type[]' value='$prod_type'&gt;
                          &lt;/td&gt;";
                      echo "&lt;td&gt;".$prod_type_code."
                              &lt;input type='hidden' name='prod_type_code[]' value='$prod_type_code'&gt;
                          &lt;/td&gt;";
                      echo "&lt;td&gt;".$qty."&lt;/td&gt;";
                      echo "&lt;td&gt;".$width."&lt;/td&gt;";
                      echo "&lt;td&gt;".$height."&lt;/td&gt;";
                      echo "&lt;td&gt;".$tot_sub."&lt;/td&gt;";
                  echo "&lt;/tr&gt;";
                  }
                  echo "&lt;tr&gt;";
                  echo "&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;
                          &lt;td&gt;
                              &lt;strong&gt;&lt;b&gt;Total:&lt;/b&gt;&lt;/strong&gt;";
                  echo "&lt;/td&gt;";
                  echo "&lt;td&gt;
                              &lt;font color='#900'&gt;&lt;u&gt;&lt;b&gt;$tots_subs&lt;/b&gt;&lt;/u&gt;&lt;/font&gt;
                          &lt;/td&gt;";
  
                  echo "&lt;/tr&gt;";
                  ?&gt;
                  &lt;/tbody&gt;
              &lt;/table&gt;
          &lt;/div&gt;
          &lt;?php 
          }
          ?&gt;
  </code></pre>
  
  <hr>
  
  <p>Since the table is in the loop. the problem is when the first table appear. and click the first header checkbox it will check all the checkbox in other table. which i dont want to happen. the one i am looking for is if there is a way i can also iterate the ID of the checkbox and its class. or there's any other way to do what i want to happen.</p>
  
  <hr>
  
  <p><img src="https://i.stack.imgur.com/ctyoH.jpg" alt="Here&#39;s a sample screen shot of the code output will be.."></p>
  
  <p>As you can see. those 3 tables have there own checkbox header where i want to be the check all inside there tables. what would be your smart idea how can i do that.</p>
  
  <p>Thanks in advance.. </p>