title: How to count checked checkboxes in different divs
body: <pre><code>&lt;head&gt;&lt;title&gt;STUDENT WISE EXAM BACKLOGS DISPLAY FOR EXAM REGISTRATION&lt;/title&gt;
  
  &lt;style type=&quot;text/css&quot;&gt;
      th {
          font-family:Arial;
          color:black;
          border:1px solid #000;
      }
      thead {
          display:table-header-group;
      }
      tbody {
          display:table-row-group;
      }
      td  {
         border:1px solid #000;   
      }
      &lt;/style&gt; 
  &lt;script type=&quot;text/javascript&quot; &gt;
  function check_value(year,sem){
  
  ysem=&quot;ys&quot;+year+sem;
  var reg=document.registration.regulation.value;
  subjectsys=&quot;subjects&quot;+year+sem;
  amountsys=&quot;amount&quot;+year+sem;
  
  if(year==1){
  if(sem==1){
  var value_list = document.getElementById(&quot;ys11&quot;).getElementsByTagName('input');
  }   
  if(sem==2){
  var value_list = document.getElementById(&quot;ys12&quot;).getElementsByTagName('input');
  }
    }elseif(year==2){
  if(sem==1){
  var value_list = document.getElementById(&quot;ys21&quot;).getElementsByTagName('input');
  }   
  if(sem==2){
  var value_list = document.getElementById(&quot;ys22&quot;).getElementsByTagName('input');
  }
    }elseif(year==3){
  if(sem==1){
  var value_list = document.getElementById(&quot;ys31&quot;).getElementsByTagName('input');
  }   
  if(sem==2){
  var value_list = document.getElementById(&quot;ys32&quot;).getElementsByTagName('input');
  }
    }elseif(year==4){
  if(sem==1){
  var value_list = document.getElementById(&quot;ys41&quot;).getElementsByTagName('input');
  }   
  if(sem==2){
  var value_list = document.getElementById(&quot;ys42&quot;).getElementsByTagName('input');
  }
    }
  
    values = 0;
    for (var i=0; i&lt;value_list.length; i++){
  if  (value_list[i].checked) {
      values=values+1;
  }
    }
    document.getElementById(subjectsys).value=values;
    if (values==&quot;0&quot;)
      {
      document.getElementById(amountsys).innerHTML=&quot;&quot;;
      return;
      }
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
        {
        document.getElementById(amountsys).innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open(&quot;GET&quot;,&quot;fee.php?year=&quot;+year+&quot;&amp;reg=&quot;+reg+&quot;&amp;sem=&quot;+sem+&quot;&amp;sub=&quot;+values,true);
    xmlhttp.send();
    } 
    &lt;/script&gt;
       &lt;/head&gt;
  
  &lt;form id=&quot;registration&quot; name=&quot;registration&quot; action=subverify.php method=POST&gt;&lt;/br&gt;&lt;/br&gt;    &lt;center&gt; Backlog Subjects for &lt;b&gt;My HtNo&lt;/b&gt;
  &lt;/br&gt;&lt;/br&gt;
  &lt;table border='1'&gt;&lt;tr&gt;
  &lt;th width='40'&gt;&amp;nbsp;&lt;/th&gt;&lt;th width='90'&gt;Regulation&lt;/th&gt;&lt;th width='40'&gt;Year&lt;/th&gt;
  &lt;th width='40'&gt;Sem&lt;/th&gt;&lt;th width='350'&gt;Subname&lt;/th&gt;
  &lt;th width='70'&gt;Internals&lt;/th&gt;&lt;th width='70'&gt;Externals&lt;/th&gt;
  &lt;/tr&gt;&lt;div id=&quot;ys41&quot;&gt;&lt;tr&gt;
  &lt;td width='40'&gt;&lt;center&gt;&lt;input type=&quot;checkbox&quot; name=&quot;sub[]&quot; value=&quot;344&quot; 
  onclick=&quot;check_value(4,1)&quot;&gt;&lt;/center&gt;&lt;/td&gt;
  &lt;td width='90'&gt;&lt;center&gt;R07&lt;/center&gt;&lt;/td&gt;&lt;td width='40'&gt;&lt;center&gt;4&lt;/center&gt;&lt;/td&gt;&lt;td     width='40'&gt;&lt;center&gt;1&lt;/center&gt;&lt;/td&gt;
  &lt;td width='350'&gt;EMBEDDED SYSTEMS&lt;/td&gt;&lt;td width='70'&gt;&lt;center&gt;18&lt;/center&gt;&lt;/td&gt;
  &lt;td width='70'&gt;&lt;center&gt;17&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=5 align=right&gt;&lt;b&gt;Subjects:     &lt;/b&gt;&lt;input size=2 type=textbox id=subjects41 name=subjects41 value=0     maxlength=2 readonly=readonly&gt;&lt;/td&gt;
  &lt;td align=right&gt;&lt;b&gt;Amount  :&lt;/b&gt;&lt;/td&gt;
  &lt;input type='hidden' name='regulation' id=regulationsubjects41 value='R07'&gt;
  &lt;td&gt;&lt;div id=&quot;amount41&quot;&gt;&lt;input type=&quot;textbox&quot; name=&quot;amountval41&quot; value=&quot;0&quot; size=&quot;5&quot;     maxlength=&quot;5&quot; readonly=&quot;readonly&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/div&gt;&lt;div id=&quot;ys42&quot;&gt;&lt;tr&gt;
  &lt;td width='40'&gt;&lt;center&gt;&lt;input type=&quot;checkbox&quot; name=&quot;sub[]&quot; value=&quot;527&quot; 
  onclick=&quot;check_value(4,2)&quot;&gt;&lt;/center&gt;&lt;/td&gt;
  &lt;td width='90'&gt;&lt;center&gt;R07&lt;/center&gt;&lt;/td&gt;&lt;td width='40'&gt;&lt;center&gt;4&lt;/center&gt;&lt;/td&gt;&lt;td     width='40'&gt;&lt;center&gt;2&lt;/center&gt;&lt;/td&gt;
  &lt;td width='350'&gt;DESIGN PATTERNS&lt;/td&gt;&lt;td width='70'&gt;&lt;center&gt;12&lt;/center&gt;&lt;/td&gt;
  &lt;td width='70'&gt;&lt;center&gt;14&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=5 align=right&gt;&lt;b&gt;Subjects:     &lt;/b&gt;&lt;input size=2 type=textbox id=subjects42 name=subjects42 value=0     maxlength=2 readonly=readonly&gt;&lt;/td&gt;
  &lt;td align=right&gt;&lt;b&gt;Amount  :&lt;/b&gt;&lt;/td&gt;
  &lt;input type='hidden' name='regulation' id=regulationsubjects42 value='R07'&gt;
  &lt;td&gt;&lt;div id=&quot;amount42&quot;&gt;&lt;input type=&quot;textbox&quot; name=&quot;amountval42&quot; value=&quot;0&quot; size=&quot;5&quot;     maxlength=&quot;5&quot; readonly=&quot;readonly&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/div&gt;&lt;tr&gt;&lt;td colspan=7&gt;&lt;center&gt;&lt;b&gt;&lt;div     id=&quot;maintotal&quot;&gt;&lt;input type=&quot;textbox&quot; name=&quot;maintotal&quot; value=&quot;0&quot; size=&quot;5&quot;     maxlength=&quot;5&quot; readonly=&quot;readonly&quot;&gt;&lt;/div&gt;&lt;/center&gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/br&gt;&lt;/br&gt;    &lt;center&gt;&lt;input type='hidden' name='htno' value='08KN1A1219'&gt;
  &lt;input type='submit' value='Register'&gt;&lt;/center&gt;&lt;/form&gt;&lt;/br&gt;
  </code></pre>
  <p>This is a output of a PHP file with using dynamic data in the form.
  I want to count only the <code>checkboxes</code> in the <code>&lt;div&gt;</code> tag and it has to display in that subjects <code>&lt;div&gt;</code> tag like <code>subjects41</code> and <code>subjects42</code>. Can anyone please help me to update this JavaScript? It passes some ajax request for displaying the fee.</p>