• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Creating an array of children

Hello Experts,

Please see this example:

http://www.differentum.com/test1.html

What I would like to do is when the user clicks a 'Select All' node, an array is populated
containing all its siblings and any of the siblings' children.

For example, if the user clicks on the top 'Select all', I want the array to contain:
44,38,61,52,37,51,49,48,3,4,5

If they click on the Select All under Sub 1 then the array should contain:
61,52,37

What do I need to do to achieve this?

Thanks!
0
jagku
Asked:
jagku
2 Solutions
 
Piotr DCommented:
What do you need to do to achieve this? First of all, you should not re-invent the wheel ;)

It would be faster/safer/better to use an already created jQuery plugins fot a checkbox tree, like either of those:

1. http://static.geewax.org/checktree/index.html
2. http://code.google.com/p/dynatree/

The latter is probably the best free plugin you can find out there (at least I did not find anything better). It appears to have already the functionality you need. Take a look at the Example browser, select "Checkbox & select", example no. 3. The plugin supports proper hierarchical selecting/deselecting and gives you methods to get selected keys/nodes. Cool, isn't it? ;)

If you need further assistance, let me know.
0
 
leakim971PluritechnicianCommented:
Test page : http://jsfiddle.net/QVmje/

$(function() {
    $(':checkbox[value="ALL"]').bind("click",function() {
        var arr = [];
        $(this).closest("ul").find(":checkbox").not(this).each(function() { arr.push($(this).val()); });
        alert(arr.join(","));
    });
});

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now