This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Check box manager: critique my jQuery plugin Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Check box manager: critique my jQuery plugin" Watch "Check box manager: critique my jQuery plugin" New topic
Author

Check box manager: critique my jQuery plugin

Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2854
    
  11

I needed a way to take a set of check boxes and associate them with another check box that would act as a "check all" for them. My goals were:

1. Checking the "check all" check box will check all the managed check boxes
2. Unchecking the "check all" check box will uncheck all the managed check boxes
3. The "check all" check box will checked, unchecked, or indeterminate depending if all, none, or some of the managed checkboxes are checked.
4. An optional callback function can be provided, which will be called when the "check all" or a managed check box is checked or unchecked, but after all the states are updated. It will be passed the set of all checked managed check boxes.

So, I looked through the existing plugins, but I didn't look too hard, because I wanted an excuse to do it myself. Here's what I've got:



Here's some code where I test it:




On the positive side, it does work. However, I'm still an advanced beginner with jQuery and I'm terrible at JavaScript, so I'm probably making all sorts of dangerous mistakes and other bad choices. I could really use your expert opinions!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Check box manager: critique my jQuery plugin