title: Multiple Parent and its Corresponding child rows table- uncheck checkbox functionality in Javascript
body: <p>I have written two functions and is called in ONCLICK of the checkboxes. FnSelAllItems(objCheckBox,objCheckAll) and FnUnSelAllItems(objCheckBox,objCheckAll). If a parent row is selected, its corresponding child rows are identified using a hidden value in a column and the child rows are also selected. </p>
  
  <p>For example if I have two parent rows and one child for each parent, and the problem arises here, IF I am checking the 1st parent's child and when I try to check the 2nd parent, its child is getting checked and the unselect function runs every time from starting and the 1st child is being unchecked since its parent was not checked. Ideally I should get the child checkboxes unchecked only when its parent is unchecked.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function fnSelAllItems(objCheckBox, objCheckAll) {
    var test;
    var j = 0;
    k = 0;
    r = 0;
    v = 0;
    var test1;
    var parent = document.all('parentRow');
    var child = document.all('ChildRow');
  
    if (parseInt(document.all('parentRow').length) &gt;= 0) {
  
      while (j &lt; parent.length)
  
      {
        if ((document.FRM_ADMIN.chkAssignUserAll(j).checked) || (typeof(document.FRM_ADMIN.chkAssignUserAll(j).checked)) == 'undefined') {
          test = parent[j].cells[1].innerText.toUpperCase(); {
            for (i = 0; i &lt; child.length; i++) {
              test1 = child[i].cells[11].innerText.toUpperCase();
              test2 = child[i].cells[1].innerText.toUpperCase();
              if ((test1 == test) &amp;&amp; test2 != "") {
  
                if (objCheckBox(i).disabled != true)
                  objCheckBox(i).checked = true;
  
              }
            }
          }
  
        }
  
        j++;
      }
  
    }
    fnUnSelAllItem(document.FRM_ADMIN.chkAssignUser, document.FRM_ADMIN.chkAssignUserAll);
  }
  
  function fnUnSelAllItems(objCheckBox, objCheckAll) {
    var test;
    var j = 0;
    k = 0;
    r = 0;
    v = 0;
    var test1;
    var row = document.all('chkAssignUserAll');
    var childrow = document.all('chkAssignUser');
    var parent = document.all('parentRow');
    var child = document.all('ChildRow');
    var test3 = parent.length;
  
  
  
    if (parseInt(document.all('parentRow').length) &gt;= 0) {
  
      while (j &lt; parent.length)
  
      {
        if ((document.FRM_ADMIN.chkAssignUserAll(j).checked == false) || (typeof(!document.FRM_ADMIN.chkAssignUserAll(j).checked)) == 'undefined') {
          test = parent[j].cells[1].innerText.toUpperCase(); {
            for (i = 0; i &lt; child.length; i++) {
              test1 = child[i].cells[11].innerText.toUpperCase();
              test2 = child[i].cells[1].innerText.toUpperCase();
              //  alert('parent'+ test+'child'+test1);
              if ((test1 == test) &amp;&amp; test2 != "") {
  
                if ((objCheckBox(i).checked = true) objCheckBox(i).checked = false;
  
                }
              }
            }
  
          }
          j++;
        }
      }
    }</code></pre>
  </div>
  </div>
  </p>