accessing subnodes in TreeView from javascript

J

Johan Åhlén

Hi,

Does anybody have any idea how to access child nodes in a TreeView
without using postbacks?

For example: in the subtree below I want to disable nodes B, C and D
when A is checked (and enable them again when A is unchecked):

Subtree:
[ ]A---[ ]B
|----[ ]C
|----[ ]D

I want to do this entirely in javascript. Any idea how to access the state
of the child nodes from the eventhandlers?

Thanks for any help!

Johan

---
Johan Åhlén
Bostadstips Sverige AB
Email: (e-mail address removed) <-- remove NOSPAM to email me
Web: http://www.bostadstips.com
Tel +46 31 842500
 
J

Johan Åhlén

Hi again,

Accessing the child nodes wasn't that much of a problem. The bigger problem
was
disabling them, which required (from what I have found) making changes in
the
control itself, to support a new attribute - "disabled".

Here is the the resulting code:

Add eventhandler:
oncheck="javascript: if (this.clickedNodeIndex != null)
__disableChildNodes(this);"

// Select and disable all child nodes under the recently clicked node
function __disableChildNodes( tree )
{
var node = tree.getTreeNode(tree.clickedNodeIndex);
var state = node.getAttribute('checked');

__setChildNodesState( node, state );
}

function __setChildNodesState( node, state )
{
var children = node.getChildren();

if ( children[0] != undefined )
{
for (var i = 0; i < children.length; i++)
{
children.setAttribute('checked',state);
children.setAttribute('disabled',state);
__setChildNodesState( children, state );
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top