title: Check all/uncheck all in foreach loop
body: <p>Please have a look on this code. How can I implement this?</p>
  
  <p><img src="https://i.stack.imgur.com/osBON.png" alt="enter image description here"></p>
  
  <p>Lately  i was done like this - </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function CheckPowerAll() {
      if (document.getElementById("PO_ALL").checked == true) {
  
          document.getElementById("PO_PowerSteering").checked = true;
          document.getElementById("PO_PowerMirrors").checked = true;
      } else {
  
          document.getElementById("PO_PowerSteering").checked = false;
          document.getElementById("PO_PowerMirrors").checked = false;
      }
  }
  &lt;/script&gt;
  
  &lt;tr&gt;
    &lt;td&gt;&lt;input name="PO_ALL" type="checkbox" id="PO_ALL" value="checkbox" onclick="CheckPowerAll()" /&gt;
  Select all &lt;span class="bold"&gt;Power Options&lt;/span&gt; &lt;/td&gt;
     &lt;/tr&gt;
   &lt;tr&gt;
  &lt;td&gt;&lt;table width="85%" border="0" cellspacing="0" cellpadding="0"&gt;
   &lt;tr&gt;
  &lt;td class="box2"&gt;
  
     &lt;input name="PO_PowerSteering" type="checkbox" id="PO_PowerSteering" value="Power Steering" /&gt;
  Power Steering&lt;br /&gt;
     &lt;input name="PO_PowerMirrors" type="checkbox" id="PO_PowerMirrors" value="Power Mirrors" /&gt;
  Power Mirrors &lt;br /&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;tr&gt;
  </code></pre>
  
  <p>But now I need to populate the value from DB.</p>
  
  <pre><code>&lt;input name="PO_ALL" type="checkbox" id="PO_ALL" value="checkbox" onclick="CheckPowerAll()" /&gt;
  Select all &lt;span class="bold"&gt;Power Options&lt;/span&gt; &lt;/td&gt;
     &lt;/tr&gt;
   &lt;tr&gt;
  &lt;td&gt;&lt;table width="85%" border="0" cellspacing="0" cellpadding="0"&gt;
   &lt;tr&gt;
  &lt;td class="box2"&gt;
  
  &lt;?php 
  
  $query = mysql_query("SELECT * FROM vehicle_poweroptions"); 
      while ( $results[] = mysql_fetch_object ($query));
        array_pop ( $results );
          foreach ( $results as $option ) : ?&gt;
  
  &lt;input name="PO_PowerWindows" type="checkbox" id="PO_PowerWindows" value="&lt;?php echo  $option-&gt;id; ?&gt;" /&gt;
  
  &lt;?php echo  $option-&gt;type; ?&gt;&lt;br /&gt;
  
  &lt;?php endforeach; ?&gt; 
  </code></pre>
  
  <p>How can I implement this?</p>