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 9174375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:44:45+00:00 2026-06-17T16:44:45+00:00

Possible Duplicate: Count the number of checkboxes selected without reloading the page? I have

  • 0

Possible Duplicate:
Count the number of checkboxes selected without reloading the page?

I have an order form that asks the User which type of pass they would like (1-3 days), and gives them the option to choose the days they want the pass for.

Currently, when they choose 3 days, my JQuery selects all 3 checkboxes for them, and deselects when they choose 1 or 2 day(s). However, what I’m trying to do is:

When they select 2 day pass, it only allows them to check a maximum of 2 boxes. When they select a 1 day pass, it only allows them to check 1 box.

I’m drawing a blank as to what needs to go in my validateDays() function – the best way to go about running this validation or whether this is actually the best route to take.

Every method I think of using requires the checkboxes to have the same Name/ID – but due to other parts of the form (omitted), they unfortunately can’t.

Any ideas / pointers?

HEAD Section JavaScript:

<script type="text/javascript">

function validateDays() {
    $('#matthewpeckham').find('input[type="checkbox"]').click(function () {
        var pass = parseInt($('input[name="other_1"]:checked').val(), 10) //1,2,3
        var days = $('#matthewpeckham').find('input[type="checkbox"]:checked').length;
        console.log(days, pass);
        if (days == pass) {
            $('#matthewpeckham').find('input[type="checkbox"]').not(':checked').prop('disabled', true);
        }
        else {
            $('#matthewpeckham').find('input[type="checkbox"]').not(':checked').prop('disabled', false);
        }
    })
    $('input[name="other_1"]').change(function () {
        $('#matthewpeckham').find('input[type="checkbox"]').prop({
            'checked': false,
            'disabled': false
        });
        if (parseInt($(this).val(), 10) == 3) $('#matthewpeckham').find('input[type="checkbox"]').prop({
            'checked': true,
            'disabled': false
        });
    });
}

</script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" ></script>

<script type="text/javascript">
$(document).ready(function() {
    jQuery('#3daypass').click(function() {
        jQuery('#other_2 , #other_3 , #other_4').prop('checked', true);
    });
    jQuery('#2daypass , #1daypass').click(function() {
        jQuery('#other_2 , #other_3 , #other_4').prop('checked', false);
    });
});

</script>

BODY Section HTML:

<input name="other_1" type="radio" value="3daypass" id="3daypass" onClick="validateDays();">
<input name="other_1" type="radio" value="2daypass" id="2daypass" onClick="validateDays();">
<input name="other_1" type="radio" value="1daypass" id="1daypass" onClick="validateDays();">

<input name="other_2" type="checkbox" id="other_2" value="Tues 5 Feb">
<input name="other_3" type="checkbox" id="other_3" value="Wed 6 Feb">
<input name="other_4" type="checkbox" id="other_4" value="Thurs 7 Feb">
  • 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-06-17T16:44:46+00:00Added an answer on June 17, 2026 at 4:44 pm

    Here’s a jQuery solution: jsFiddle example

    $('input[type="checkbox"]').click(function () {
        var pass = parseInt($('input[name="other_1"]:checked').val(), 10) //1,2,3
        var days = $('input[type="checkbox"]:checked').length;
        console.log(days, pass);
        if (days == pass) {
            $('input[type="checkbox"]').not(':checked').prop('disabled', true);
        }
    })
    $('input[name="other_1"]').change(function () {
        $('input[type="checkbox"]').prop({
            'checked': false,
                'disabled': false
        });
        if (parseInt($(this).val(), 10) == 3) $('input[type="checkbox"]').prop({
            'checked': true,
                'disabled': false
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: NSNumber retain count issue Hello, I have the following code: NSNumber *number
Possible Duplicate: Count(*) vs Count(1) If I have a table, 'id' is primary key,
Possible Duplicate: Count specific character occurances in string I have a delimeter in string
Possible Duplicate: Array value count javascript I have an array which contains several duplicates,
Possible Duplicate: Random number generator only generating one random number Random not that random
Possible Duplicate: How can I count the numbers of rows that a mysql query
Possible Duplicate: How to count the number of lines in an Objective-C string (NSString)?
Possible Duplicate: How do we count rows using Hibernate? I want count number of
Possible Duplicate: Best algorithm to count the number of set bits in a 32-bit
Possible Duplicate: How to efficiently count the number of keys/properties of an object in

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.