![]() |
some javascript help: automating checkboxes with jquery - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: some javascript help: automating checkboxes with jquery (/showthread.php?tid=15175) |
some javascript help: automating checkboxes with jquery - El Forum - 01-28-2009 [eluser]Bramme[/eluser] Hey all I have a two dimensional unordered list on my website that lists a navigation: main elements in the first list and their subpages in sublists. Each page has a checkbox that's used to enable/disable certain pages for certain users. When you're not allowed to visit the subpages of an item, it offcourse doesn't make sense to put that item in the nav in the first place, so for usability's sake, I wanted some javascript that handled the checkboxes as follows: When you select/deselect a main item all subitems get automatically selected/deselected as well. When you deselect/select all subitems of one category, the main category get's deselected/selected too. One last thing: when all is deselected, and you select a subitem, the main item has to get checked too. Now I whipped up some jQuery that actually works, but I was wondering if there's any better way of doing this... My second function looks too complicated, but I'm afraid I don't know jQuery well enough... Here's my code: Code: $(document).ready( function () { changed the code to this Code: $(document).ready( function () { |