• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Check box manager: critique my jQuery plugin

 
Greg Charles
Sheriff
Posts: 2993
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic