Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
945
Need JavaScript function to clear checkboxes
posted

Hello,

I need to be able to clear out all checkboxes in my treeview via javascript. I tried guessing on what the function might be:

var control = $find('<%=selectuser.ClientID %>');
checkedItems = control.get_checkedNodes();
for (var i = 0; i < checkedItems.length; i++) {
     checkedItems[i].set_checkState() = 0;
}

but this didn't work as the items still displayed a check in the checkbox.  Can I please be given the syntax to clearing out all checkboxes on clientside?

 

Thanks.

Parents
No Data
Reply
  • 49378
    posted

    Hello Shane,

    Thank you for posting in the community.

    As set_checkState is a function the desired state value should be passed as a parameter to it.

    Please note that after unchecking a node, the checked nodes collection of the tree would also be automatically updated. Below is a sample function for deselecting all tree nodes:

    Code Snippet
    1. function deselectNodes() {
    2.     var control = $find('<%=WebDataTree1.ClientID %>');
    3.  
    4.     while (control.get_checkedNodes().length > 0) {
    5.         control.get_checkedNodes()[0].set_checkState(0);
    6.     }
    7.  
    8.  
    9. }

    Hope this helps.

Children