Do Checkboxes Have a Limitation

Posted on 2004-11-16
Last Modified: 2010-04-17
I've got a form with many, many checkboxes MOST with the same name (zipselect). If too many (I have not determined what the failure number is) are selected, the form will not submit.

Question 1: Is there a limitation of the number of checkboxes allowed?

Question 2: How can I stop the submission and post an alert if say more that 100 zipselect check boxes are selected and NOT count my other set of checkboxes (propertytype) against the maximum allowed? Does the function have to be assigned to the button onclick or can it be assigned to the onsubmit?

Question by:webdork
    LVL 8

    Expert Comment

    I am not aware of any checkbox limitations, but there are limits to the amount of data you can pass in a single request
    Check here for a lot of info
    LVL 8

    Expert Comment

    oh and regarding Q2, I would put it in the onsubmit to cover submission without clicking (enter for example)


    This file retrieved from the JS-Examples archives
    1000s of free ready to use scripts, tutorials, forums.
    Author: JS-Examples -


    function cntprimary(cnt){
       for(i=1; i<=8; i++){
       var enc=eval("document.nameofform.checkbox"+i+".checked");
       return cnt;
    <form name=nameofform>
    <input type="radio" name="checkbox1" value="check me">
    <input type="radio" name="checkbox2" value="check me">
    <input type="radio" name="checkbox3" value="check me">
    <input type="radio" name="checkbox4" value="check me">
    <input type="radio" name="checkbox5" value="check me">
    <input type="radio" name="checkbox6" value="check me">
    <input type="radio" name="checkbox7" value="check me">
    <input type="radio" name="checkbox8" value="check me">
    <BR><a href="javascript:alert(cntprimary())">how many?</a>

    <BR><center><a href=''></a></center>

    Author Comment

    Q1: Thanks, good info there.

    Q2: Of course those are radio buttons not checkboxes. And I don't want to count I want to stop the submission and show an alert if the max is exceeded.
    LVL 8

    Expert Comment

    you mean there are loads of radio button groups, or many radio buttons in a group?
    the script i posted works for radio buttons too but it largely depends on a naming scheme.
    You could go the naming scheme route (possibly defining them in an array) or loop through form elements. There are plenty of cut and paste scripts available if  you google, but you're best at finding your optimal script.
    If you want to cancel form submission, make a function (myfunction) that returns true or false depending on the selection, then in the onsubmit of the form put return myfunction
    function myfunction()
    if (countboxes()>treshold)
         return false;

    return true;

    <form onsubmit="return myfunction()">
    LVL 8

    Accepted Solution

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <script language="Javascript">
    function isValid(formRef){
    //get number of form elements
    var cnt_of_controls = formRef.elements.length;
    //define counter
    var cnt_of_selectedboxes=0;

    //loop through form items
       //see if it's a checkbox
       if(formRef.elements[i].type == "checkbox"){
           // see if it's checked
          if(formRef.elements[i].checked == true){
              //count it
            cnt_of_selectedboxes ++;

    // if to many selections
    if (cnt_of_selectedboxes>100)
      /cancel submit
     return false;
    return true;


    <form name="someForm" action="" onSubmit="return isValid(this)">
    <input type="checkbox" name="cb1">Check Box One<br>
    <input type="checkbox" name="cb2">Check Box Two<br>
    <input type="checkbox" name="cb3">Check Box Three<br>
    <input type="checkbox" name="cb4">Check Box Four<br>
    <input type="checkbox" name="cb5">Check Box Five<br>
    <input type="Submit" value="Submit">

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    This article will show, step by step, how to integrate R code into a R Sweave document
    A short article about problems I had with the new location API and permissions in Marshmallow
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now