title: selecting all checkboxes in javascript - with array of different values for checkbox
body: <p>JavaScript Code</p>
  
  <pre><code>function toggle(source) {
  
    console.log('here');
    checkboxes = document.getElementsByName('checkbox[]');
  
    for(var i=0, n=checkboxes.length;i&lt;n;i++) {
         checkboxes[i].checked = source.checked;
      }
   }
  </code></pre>
  
  <p>PHP Code generating all checkboxes dynamically</p>
  
  <pre><code>    &lt;td&gt;&lt;input name="checkbox[&lt;?php echo $row['id']?&gt;]" type="checkbox" id="checkbox" value="&lt;?php echo $row['id']; ?&gt;"&gt;&lt;/td&gt;
  </code></pre>
  
  <p>According to PHP code above 
  All the name values are generated dynamically.
  Javascript code above is not able to select all the checkboxes</p>
  
  <p>Please help!</p>
  
  <hr>
  
  <p>After very long research finally found anser for my critical problem - Selecting &amp; checking all the checkboxes with different name, value, id and same type.</p>
  
  <pre><code>function toggle (source) {
  var checkboxes;
  var len = document.frm1.elements.length;
  var x = document.getElementById('all');
  
  for(var i = 0 ; i&lt; len;i++){
  
      if(document.frm1.elements[i].type == "checkbox")
          {
  
          checkboxes = document.frm1.elements[i];
          if(x.checked == true)
          {
              document.frm1.elements[i].checked = true;
          }
          else
          {
              document.frm1.elements[i].checked = false;
          }
             }
  
       /*if( isAllCheck == false ){
          document.frm1.elements[i].checked = "true";
          //alert( "it is false" );
      }else{ 
          document.frm1.elements[i].checked = "false";
          //alert( "it is true" );
      }
     isAllCheck = !isAllCheck; */
  
  
              }
       console.log(checkboxes);
       for(var i=0, n=checkboxes.length;i&lt;n;i++) {
  
  checkboxes[i].checked = source.checked;
  
         }
  </code></pre>
  
  <p>I hope this would help others...</p>