[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 523
  • Last Modified:

JavaScript function to check/unckeck TreeView

Hi Experts,

How can I use javascript to check/uncheck all child nodes (one level down) then the checkBox of a treeView node is changed?

Also when a checkBox is UnCkecked how can I make sure its parent is also unchecked?

thanks a lot
0
kateL
Asked:
kateL
  • 2
1 Solution
 
sabeeshCommented:
function UncheckAllNode(check)
   {
        var src=null;
        var treeview = document.getElementById("_treeGroup"); //use your treeview id instead of Tree1
        var treeLinks = treeview.getElementsByTagName("a");      
        for(i=0;i<treeLinks.length;i++)
         {
           src=treeLinks[i].firstChild;
           var parentTable = GetParentByTagName("table", src);
           var nxtSibling = parentTable.nextSibling;
            if(nxtSibling && nxtSibling.nodeType == 1)//check if nxt sibling is not null & is an element node
            {
                if(nxtSibling.tagName.toLowerCase() == "div") //if node has children
                {              
                    //check or uncheck children at all levels
                    CheckUncheckChildren(parentTable.nextSibling,check);
                }
            }
            var childChkBoxes = parentTable.getElementsByTagName("input");  //check or uncheck the all main node
            childChkBoxes[0].checked=check;      
        }      
   }

0
 
kateLAuthor Commented:
Hi sabeesh, that function is supposed to check all nodes in the treeView. Not check the child nodes of a particular node which is what I want.

And it crashes

It has things like getElementsByTagName("a"), GetParentByTagName("table", src), getElementsByTagName("input") ... which are not applicable. I don't have "a", "table" or "input" defined anywhere.

Can you please explain the code and how I can tweak it to do what I want?

Thanks sabeesh
0
 
kateLAuthor Commented:
Thank a lot kvimal
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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