Javascript Error

I Have a Rad Treeview with checkboxes enabled and with a JavaScript that "checks" the parent and it's group if a child node is checked...(See Code).
Works fine...

HOWEVER...
If I click a "top" parent item I get a java error...of course.

I need to change the script so that if the parent is checked all children get checked and keep the same script that is working now.
How
--TreEVIEW------------
=====================================================
<telerik:RadTreeView runat="server" ID="RadTreeView1" DataSourceID="SqlDataSource1"
                    DataFieldID="id" DataFieldParentID="parentID" CheckBoxes="true" CheckChildNodes="true"
                    OnClientNodeChecked="checkChange">
                    <DataBindings>
                        <telerik:RadTreeNodeBinding TextField="panelText" ValueField="id" />
                        <telerik:RadTreeNodeBinding Depth="0" Checkable="True" TextField="panelText" ValueField="id"
                            Expanded="true" />
                    </DataBindings>
                </telerik:RadTreeView>

==================================================
--Java Script
==================================================
 <script type="text/javascript">
        function checkChange(sender, args) {
            var checkedNode = args.get_node();
            if (checkedNode.get_checked()) {
                checkedNode.get_parent().set_checked(true);
            }
        }
    </script>

Open in new window

Larry Bristersr. DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VenabiliCommented:
As for your error - simply check if this is not the top:
(checkedNode.get_parent() == checkedNode.get_treeView())
or
(checkedNode.get_level() == 0)  
before calling set_checked()
This will make sure that you do not call illegal methods (if I remember my syntax properly that is)

Do you need any help on the other part (set all children as checked)?
0
Larry Bristersr. DeveloperAuthor Commented:
Venabili:
Sorry...but I don't know how that would look or be palced in my JavaScript above.
0
VenabiliCommented:
Replace
checkedNode.get_parent().set_checked(true);
with
if (checkedNode.get_parent() != checkedNode.get_treeView()) {
    checkedNode.get_parent().set_checked(true);
}

PS: http://www.telerik.com/help/aspnet-ajax/treeview-get-parent.html  for exact syntax and the second choice
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Larry Bristersr. DeveloperAuthor Commented:
excellent!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.