jQuery Plugin – Checkbox Manipulation


Various plugins for working with checkboxes.

Source code available from GitHub or a Zipped download.

Sample form #myform

  Last Name First Name Title
Davolio Nancy Sales Representative
Fuller Andrew Vice President, Sales
Leverling Janet Sales Representative
Peacock Margaret Sales Representative
Buchanan Steven Sales Manager
Suyama Michael Sales Representative
King Robert Sales Representative
Callahan Laura Inside Sales Coordinator
Dodsworth Anne Sales Representative

toggleCheckboxes

Use: $("#myform").toggleCheckboxes(); to toggle all checkboxes in ‘#myform’.

Ignore checkboxes matching a jQuery expression : $("#myform").toggleCheckboxes(":not(#checkbox1)");

Return the checked items: $("#myform").toggleCheckboxes(".top5", true);
(use “*” instead of “.top5″ if you want to toggle all of them)

checkCheckboxes

Use: $("#myform").checkCheckboxes(); to check all checkboxes in ‘#myform’.

Ignore checkboxes matching a jQuery expression : $("#myform").checkCheckboxes(":not(#checkbox1)");

Return the checked items: $("#myform").checkCheckboxes(".top5", true);
(use “*” instead of “.top5″ if you want to check all of them)

unCheckCheckboxes

Use: $("#myform").unCheckCheckboxes(); to uncheck all checkboxes in ‘#myform’.

Ignore checkboxes matching a jQuery expression : $("#myform").unCheckCheckboxes(":not(#checkbox1)");

Return the unchecked items: $("#myform").unCheckCheckboxes(".top5", true);
(use “*” instead of “.top5″ if you want to uncheck all of them)

radioCheckboxGroup

Makes all checkboxes with the given name behave like a radio button list. Code was originally written by ‘Rob D’ in an email sent to me.

Use: $.radioCheckboxGroup("name").

You can also filter using an expression: $.radioCheckboxGroup("name", ".myclass");

If you use a blank string "", or null instead of "name", it will apply to all checkboxes on the page.

The checkboxes that this is applied to can still be checked via JavaScript (i.e. using toggleCheckboxes or checkCheckboxes).