title: Javascript function to enable submit button when checkboxes are checked
body: <p>I am trying to write a Javascript function that will be called whenever a checkbox is clicked, and will check how many checkboxes are checked in total, and will then either enable or disable the form submit button, depending on how many checkboxes are checked.</p>
  
  <p>What I have is of this form:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  
  &lt;script type="text/javascript" language="JavaScript"&gt;
  
  function enabledisablenext()
  {
      var boxeschecked = 0;
      for (var i = 0; i&lt; 99; i++) {
          if(document.getElementById("transcheck" + i).checked == true){ 
          boxeschecked ++;
          }
      }
      if (boxeschecked == 0) {document.getElementById("next").disabled= true;}
      if (boxeschecked != 0) {document.getElementById("next").disabled= false;}
  }
  &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;form action='something.php' method='POST'&gt;
  
  &lt;input type='checkbox' id='transcheck1' onclick="enabledisablenext()"/&gt;
  &lt;input type='checkbox' id='transcheck2' onclick="enabledisablenext()"/&gt;
  &lt;input type='checkbox' id='transcheck3' onclick="enabledisablenext()"/&gt;
  &lt;input type='checkbox' id='transcheck4' onclick="enabledisablenext()"/&gt;
  &lt;input type='checkbox' id='transcheck5' onclick="enabledisablenext()"/&gt;
  
  &lt;input type='submit' disabled='disabled' id='next'/&gt;&lt;p&gt;&lt;/p&gt;
  
  &lt;/form&gt;                          
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>However, this isn't working. The submit button is not enabled when 1 or more checkboxes are checked. Can someone see where I went wrong?</p>
  
  <p>Thanks!</p>