JavaScript function to check/unckeck TreeView

Posted on 2007-07-26
Last Modified: 2012-05-05
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
Question by:kateL
    LVL 8

    Expert Comment

    function UncheckAllNode(check)
            var src=null;
            var treeview = document.getElementById("_treeGroup"); //use your treeview id instead of Tree1
            var treeLinks = treeview.getElementsByTagName("a");      
               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
                var childChkBoxes = parentTable.getElementsByTagName("input");  //check or uncheck the all main node


    Author Comment

    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
    LVL 5

    Accepted Solution


    Author Comment

    Thank a lot kvimal

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now