Topic: JQuery | Checkbox checkboxes tree menu

Hi All,

In my recent project  i need to create tree menu through and each item contains a checkbox. user can select both parent and child checkbox.

Structure is something like

- parent chkbox
- - child chkbox
- - child chkbox
- parent chkbox
- - child chkbox
- - child chkbox

Condition needs to implement are:

- As described above user can select both parent and child checkbox.
- If any of the child checkbox is selected then it parent get selected too and vice versa.
- Need to take care of code resuability (means without any hardcoding id or class) as i have to use it on number of places. by passing parameter to a method. for example something like function selectbox (selection){  } would be great.

Any pointer or help would be highly appreciable..

Thanks in advance.
Muckoda

Help people to get helped by people

Re: JQuery | Checkbox checkboxes tree menu

Do you have any code to start with. Have you thought about the HTML structure? From what it sounds like you're describing, the parent checkbox has independent functionality - meaning that if it is checked/unchecked - nothing happens to the children checkboxes, and if the child checkbox is checked/unchecked, then it's corresponding parent checkbox is checked/unchecked depending on the status of its child.

As far as code reusability goes - to me it would make more sense to give some sort of id/class, rather than creating a function where you could pass a variable. If you use a class/classes you'll have reusability because classes can be used multiple times on a page (if that's your main concern).

Daniel Marino | www.iamdanielmarino.com

Re: JQuery | Checkbox checkboxes tree menu

Not that I was trying to do your homework for you smile but I came up with a demo as to how this could work: http://iamdanielmarino.com/projects/par … checkboxes

*Update: My coworker found this also which is much cooler than my demo: http://code.google.com/p/jquery-tristate-checkbox/

Last edited by dmarino (2010-09-17 06:12:12)

Daniel Marino | www.iamdanielmarino.com