title: Limiting user for number of checkboxes to checked
body: <p>I am trying to develop a page in which there are many check boxes but user is restricted to check only 2 checkboxes. I got this code but it is not working as i am giving it a name as array. Please suggest how to use this name for check boxes when calling th javascript function.</p>
  
  <pre class="lang-js prettyprint-override"><code>function checkboxlimit(checkgroup, limit){
      var checkgroup=checkgroup;
      var limit=limit;
      for (var i=0; i&lt;checkgroup.length; i++){
          checkgroup[i].onclick=function(){
              var checkedcount=0;
              for (var i=0; i&lt;checkgroup.length; i++)
                  checkedcount+=(checkgroup[i].checked)? 1 : 0;
              if (checkedcount&gt;limit){
                  alert("You can only select a maximum of "+limit+" checkboxes");
                  this.checked=false;
              }
          }
      }
  }
  checkboxlimit(document.forms.world.seatdata, 2);
  </code></pre>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form id="world" name="world"&gt;
  &lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|12' id="A11" /&gt;
    &lt;label for="A11"&gt;A11&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|11' id="A10"  /&gt;
    &lt;label for="A10"&gt;A10&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|10' id="A9"  /&gt;
    &lt;label for="A9"&gt;A9&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|9' id="A8"  /&gt;
    &lt;label for="A8"&gt;A8&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|6' id="A7"  /&gt;
    &lt;label for="A7"&gt;A7&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|5' id="A6"  /&gt;
    &lt;label for="A6"&gt;A6&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|4' id="A5"  /&gt;
    &lt;label for="A5"&gt;A5&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|3' id="A4"  /&gt;
    &lt;label for="A4"&gt;A4&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|2' id="A3" /&gt;
    &lt;label for="A3"&gt;A3&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|1' id="A2" /&gt;
    &lt;label for="A2"&gt;A2&lt;/label&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;input type='checkbox' name='seatdata[]' value='0|0' id="A1" unchecked /&gt;
    &lt;label for="A1"&gt;A1&lt;/label&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>