Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7511261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:29:42+00:00 2026-05-29T23:29:42+00:00

My HTML form contains many checkbox groups,I want to check if atleast one checkbox

  • 0

My HTML form contains many checkbox groups,I want to check if atleast one checkbox is selected from every group.

For example

// Group vehicle
<input type="checkbox" name="vehicle" value="Bike"/> I have a bike<br />
<input type="checkbox" name="vehicle" value="Car"/> I have a car <br/>   

// Group language
<input type="checkbox" name="language" value="JS"/> I am JS Ninja <br/>
<input type="checkbox" name="language" value="Android"/> I am a droid <br/>   

I can use following Jquery selector to check if at least one checkbox is selected

if($(":checkbox:checked[vehicle]").length) > 1
if($(":checkbox:checked[language]").length) > 1  

But I have to repeat this selector for every checkbox group. My page contains many checkbox groups. Is there any other way by which I can select all checkbox groups in single jquery selector?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:29:45+00:00Added an answer on May 29, 2026 at 11:29 pm

    Updated as promised, once I had the time to fully test the original example code. I see you guys went a little overboard, it only needed some minor adjustments to function 😀

    I also made it a bit more efficient by not repeating the jQuery checkbox selectors multiple times.

    And the result:

    <html>
    <head>
        <script type="text/javascript" src="jquery-1.7.1.min.js"></script>
        <script type="text/javascript">
            function checkedTest() {
                var nameArr = new Array();
                var finalResult = true;
                var allCheckboxes = $("input[type=checkbox]");
    
                // Put all the unique name attributes in an array.
                allCheckboxes.each(function(){
                    var name = $(this).attr("name");
                    if($.inArray(name, nameArr) == -1)
                        nameArr.push(name);
                });
    
                // Go through each name attribue and make sure at least one is checked.
                $.each(nameArr, function(index, value){
                    if(allCheckboxes.filter("[name=" + value + "]:checked").length == 0)
                        finalResult = false;
                });
    
                return finalResult;
            }
        </script>
    </head>
    <body>
        Group1Box1: <input type="checkbox" id="group1Box1" name="group1"/>
        Group1Box2: <input type="checkbox" id="group1Box2" name="group1"/>
        <br/>
        Group2Box1: <input type="checkbox" id="group2Box1" name="group2"/>
        Group2Box2: <input type="checkbox" id="group2Box2" name="group2"/>
        <br/>
        Group3Box1: <input type="checkbox" id="group3Box1" name="group3"/>
        Group3Box2: <input type="checkbox" id="group3Box2" name="group3"/>
        <br/><br/>
        <input type="button" value="Test!" onclick="alert(checkedTest());"/>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML form that contains many links (around 17). I want, when
I have a html form which contains group of radio buttons. When one of
I have an asp.net form that contains some html, 2 controls a calendar from
I have a form in HTML which contains multiple same name fields. For example:
A date selection HTML form section contains two drop downs - one for the
If a HTML form contains multiple input fields: <form> <input id=in1 type=text value=one> <input
I have just a basic html form within index.php which contains two text fields:
I have a web site that contains an HTML form, in this form I
In my HTML code, I have a form tag that contains two input boxes,
I have a simple HTML Form with one column having a select menu with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.