title: "SELECT ALL" Checkbox for Values Retrieved by Foreach Loop
body: <p>I am trying to pass the values from multiple forms.</p>
  
  <p>Reference: <a href="https://stackoverflow.com/questions/16828478/check-all-uncheck-all-in-foreach-loop">Check all/uncheck all in foreach loop</a></p>
  
  <p>I have checked out a very useful post in SO that enables me to send values to process with a SELECT ALL checkbox.</p>
  
  <p>My values are generated from SQL query in controller thus I am using the codes below:</p>
  
  <pre><code>             &lt;div class="col" id="one"&gt;
                &lt;fieldset&gt;
                  &lt;form action="{$link-&gt;getLink('controller')|escape:'htmlall':'utf-8'}" method="post"&gt; 
                      &lt;p&gt;
                        &lt;input name="ALL" type="checkbox" id="check-all2" value="checkbox" onclick="CheckAll()" /&gt;
                        &lt;label&gt;SELECT ALL&lt;/label&gt;
                         &lt;br/&gt;&lt;br/&gt;
                         {foreach from=$payment item=row}
                         &lt;input type="checkbox" name="payment[]" maxlength="50" value={$row.id_order} class="payment"&gt;
                         &lt;label&gt; ID: &lt;b&gt;{$row.id_order}&lt;/b&gt;&lt;/label&gt;&lt;br/&gt;
                         {/foreach}
                         &lt;br/&gt;
                        &lt;input id="submit" name="submitpayment" type="submit" value="PACK ITEMS" class="button" /&gt;
                      &lt;/p&gt;
                    &lt;/form&gt;
                  &lt;/fieldset&gt;
              &lt;/div&gt;
  </code></pre>
  
  <p>jQuery: </p>
  
  <pre><code>  function CheckAll() {
  var elements = document.getElementsByName("payment");
  var l = elements.length;
  
  if (document.getElementById("check-all2").checked) {
      for (var i = 0; i &lt; l; i++) {
          elements[i].checked = true;
      }
  } else {
      for (var i = 0; i &lt; l; i++) {
          elements[i].checked = false;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is working currently for me, unfortunately I am unsure how to create for multiple forms.</p>