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

  • SEARCH
  • Home
  • 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 6798473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:44:04+00:00 2026-05-26T18:44:04+00:00

I want to stop the user to check another checkbox after a certain number

  • 0

I want to stop the user to check another checkbox after a certain number of checkboxes have been checked already. i.e. After 3 checkboxes are checked, the user cannot check anymore and a message says ‘You’re not allowed to choose more than 3 boxes.’

I’m almost there but the last checkbox is still being checked and I don’t want that, I want it to be unchecked with the message appearing.

How do I do that:

var productList = $('.prod-list'),
    checkBox = productList.find('input[type="checkbox"]'),
    compareList = $('.compare-list ul');

productList.delegate('input[type="checkbox"]', 'click', function () {
  var thisElem = $(this),
      thisData = thisElem.data('compare'),
      thisImg = thisElem.closest('li').find('img'),
      thisImgSrc = thisImg.attr('src'),
      thisImgAlt = thisImg.attr('alt');

  if (thisElem.is(':checked')) {
    if ($('input:checked').length < 4) {

        compareList.append('<li data-comparing="' + thisData + '"><img src="' + thisImgSrc + '" alt="'+ thisImgAlt +'" /><li>');

    } else {
        $('input:checked').eq(2).attr('checked', false);
        alert('You\'re not allowed to choose more than 3 boxes');
    }
  } else {
    var compareListItem = compareList.find('li');

    for (var i = 0, max = compareListItem.length; i < max; i++) {
        var thisCompItem = $(compareListItem[i]),
            comparingData = thisCompItem.data('comparing');

        if (thisData === comparingData) {
            thisCompItem.remove();
        }
    }

  }

});
  • 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-26T18:44:04+00:00Added an answer on May 26, 2026 at 6:44 pm

    I might have misunderstood the question… see my comment.

    Too prevent the selection, you can call event.preventDefault() and define the handler with the event parameter.

    $('input[type="checkbox"]').click(function(event) {
        if (this.checked && $('input:checked').length > 3) {
            event.preventDefault();
            alert('You\'re not allowed to choose more than 3 boxes');
        }
    });
    

    DEMO

    Alternatively, set this.checked to false. This will even prevent the browser from rendering the checkmark.

    DEMO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want anonymous user can view projects' status and logs but can not start/stop/force
picturebox1.image = image.fromfile(c:/anim.gif) after i import the animation, i want to Stop the animation
I have one image animation started using GameQuery. Now I want to stop the
I have a form with several ingredients on it. I want a user to
I want to 'postpone' (stop the default behavior of the form) sending the user
I want to be able to check for specific conditions when a user selects
I want to check a data version number in my XML and if the
Hi i have mvc2 application where i want to stop processing application when settings
When a user saves a form, I want to do the following check before
I want to stop the end users from being able to resize a GUI

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.