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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:58:39+00:00 2026-06-02T03:58:39+00:00

The mind boggles – my colleague sent me this script – I am sure

  • 0

The mind boggles – my colleague sent me this script – I am sure I overlook something simple

http://jsfiddle.net/mplungjan/j4m62/

which for some reason I cannot figure out, checks all three checkboxes regardless of which I click – I would expect only the first two to be checked on click of either of the first two and the third to be checked on its own

HTML:

<input class="check-all" name="checkbox[]"  id="checkbox1" type="checkbox" value="on"/><label for="checkbox1">Check 1&2</label><br/>

<input class="check-allfeatured" name="checkbox[]"  id="checkbox2"  type="checkbox" value="on"/><label for="checkbox2">Check 1&2</label><br/>

<input class="check-alldel" name="deleteids[]"  id="deleteids1"  type="checkbox" value="on"/><label for="deleteids1">Check this only</label>

JavaScript:

$(document).ready(function(){
  $('.check-all:checkbox').click(function(event) {
      var group = 'input:checkbox[name=' + $(this).attr('name') + ']';
      console.log(group+':'+event.target.checked);
      $(group).each(function(){
          $(this).attr("checked",event.target.checked);
      });
  });

  $('.check-alldel:checkbox').click(function(event) {
      var group = 'input:checkbox[name=' + $(this).attr('name') + ']';
      console.log(group+':'+event.target.checked);
      $(group).each(function(){
          $(this).attr("checked",event.target.checked);
      });
   });

  $('.check-allfeatured:checkbox').click(function(event) {
      var group = 'input:checkbox[name=' + $(this).attr('name') + ']';
      console.log(group+':'+event.target.checked);
      $(group).each(function(){
          $(this).attr("checked",event.target.checked);
      });
  });
});
  • 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-02T03:58:41+00:00Added an answer on June 2, 2026 at 3:58 am

    While not pretty, the corrected version is here: http://jsfiddle.net/j4m62/8/

    Your problem was that you were not putting quotes around the names of your checkbox name assertion.

    Change:

    var group = 'input:checkbox[name=' + $(this).attr('name') + ']';
    

    into:

    var group = 'input:checkbox[name="' + $(this).attr('name') + '"]';
    

    and you will get the behavior you are expecting. But you really have a lot of duplicated code so you should probably refactor since you are performing the same operation regardless of the checkbox clicked. Check this out.

    Thanks @limelights for pointing out that I forgot to explicitly pass event in. Updated link.

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

Sidebar

Related Questions

This one boggles my mind. I've used this same script (different targets of course)
Losing my mind on this one.. How can I do something as simple as..
This is probably something mind-numbingly obvious, but I'm new to c# so be gentle...
Ok, folks. I've never encountered this before and it boggles the mind and is
This is blowing my mind because it's probably an easy solution, but I can't
In my mind, a web app something that runs continuously; therefore, I'm confused by
Mind has gone blank this afternoon and can't for the life of me figure
an abstract in my mind is something like idontknow x = (idontknow) findViewById(R.string.stringname); so
I have in mind a construct like this: template <typename T, T defaultValue> struct
My mind seems to be going blank on this one. I have to write

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.