?
Solved

Check all checkboxes in a treeview

Posted on 2006-07-24
5
Medium Priority
?
956 Views
Last Modified: 2009-07-29
In my ASP.Net 2.0 C# application, I have a page with two treeviews.
Each node of the treeviews has a checkbox.

I need a method of checking/unchecking all of the checkboxes
on the individual treeviews.  Can I do this in Javascript?

Thanks.
0
Comment
Question by:JeffDrummond
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 17167296
Go to browser and copy the complette page html source with both treeviews here as text.

0
 

Author Comment

by:JeffDrummond
ID: 17167435
The page is quite large.  This is the portion inculding the two treeviews, Regions and Categories.  Thanks!

 <table width="350">
                        <tr>
                            <td valign="top">
                                Regions:&nbsp;</td><td>Categories:</td>
                        </tr>
                        <tr>
                            <td align="left" valign="top">
                                <a href="#ctl00_Body_RegionsTreeview_SkipLink"><img alt="Skip Navigation Links." src="/WebResource.axd?d=-ZmMyGfj3hopVa_HZUpeJg2&amp;t=632883495870637959" width="0" height="0" style="border-width:0px;" /></a><div id="ctl00_Body_RegionsTreeview">
      <table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX2SfMWA3mIjcL_y6D_rPDZQ1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_RegionsTreeviewn0CheckBox" id="ctl00_Body_RegionsTreeviewn0CheckBox" checked="checked" title="Asia" /><a class="ctl00_Body_RegionsTreeview_0" href="javascript:__doPostBack('ctl00$Body$RegionsTreeview','sAsia')" onclick="TreeView_SelectNode(ctl00_Body_RegionsTreeview_Data, this,'ctl00_Body_RegionsTreeviewt0');" id="ctl00_Body_RegionsTreeviewt0">Asia</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX-EvRUG_TP5UCG1aTnSOUWY1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_RegionsTreeviewn1CheckBox" id="ctl00_Body_RegionsTreeviewn1CheckBox" title="Africa" /><a class="ctl00_Body_RegionsTreeview_0" href="javascript:__doPostBack('ctl00$Body$RegionsTreeview','sAfrica')" onclick="TreeView_SelectNode(ctl00_Body_RegionsTreeview_Data, this,'ctl00_Body_RegionsTreeviewt1');" id="ctl00_Body_RegionsTreeviewt1">Africa</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX-EvRUG_TP5UCG1aTnSOUWY1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_RegionsTreeviewn2CheckBox" id="ctl00_Body_RegionsTreeviewn2CheckBox" checked="checked" title="North America" /><a class="ctl00_Body_RegionsTreeview_0" href="javascript:__doPostBack('ctl00$Body$RegionsTreeview','sNorth America')" onclick="TreeView_SelectNode(ctl00_Body_RegionsTreeview_Data, this,'ctl00_Body_RegionsTreeviewt2');" id="ctl00_Body_RegionsTreeviewt2">North America</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX-EvRUG_TP5UCG1aTnSOUWY1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_RegionsTreeviewn3CheckBox" id="ctl00_Body_RegionsTreeviewn3CheckBox" title="South America" /><a class="ctl00_Body_RegionsTreeview_0" href="javascript:__doPostBack('ctl00$Body$RegionsTreeview','sSouth America')" onclick="TreeView_SelectNode(ctl00_Body_RegionsTreeview_Data, this,'ctl00_Body_RegionsTreeviewt3');" id="ctl00_Body_RegionsTreeviewt3">South America</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX-EvRUG_TP5UCG1aTnSOUWY1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_RegionsTreeviewn4CheckBox" id="ctl00_Body_RegionsTreeviewn4CheckBox" title="Europe" /><a class="ctl00_Body_RegionsTreeview_0" href="javascript:__doPostBack('ctl00$Body$RegionsTreeview','sEurope')" onclick="TreeView_SelectNode(ctl00_Body_RegionsTreeview_Data, this,'ctl00_Body_RegionsTreeviewt4');" id="ctl00_Body_RegionsTreeviewt4">Europe</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX4iascjIf74mJB0-PvYVJWk1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_RegionsTreeviewn5CheckBox" id="ctl00_Body_RegionsTreeviewn5CheckBox" title="Australia" /><a class="ctl00_Body_RegionsTreeview_0" href="javascript:__doPostBack('ctl00$Body$RegionsTreeview','sAustralia')" onclick="TreeView_SelectNode(ctl00_Body_RegionsTreeview_Data, this,'ctl00_Body_RegionsTreeviewt5');" id="ctl00_Body_RegionsTreeviewt5">Australia</a></td>
            </tr>
      </table>
</div><a id="ctl00_Body_RegionsTreeview_SkipLink"></a>
                            </td>
                            <td align="left" valign="top">
                                <a href="#ctl00_Body_CategoriesTreeView_SkipLink"><img alt="Skip Navigation Links." src="/WebResource.axd?d=-ZmMyGfj3hopVa_HZUpeJg2&amp;t=632883495870637959" width="0" height="0" style="border-width:0px;" /></a><div id="ctl00_Body_CategoriesTreeView">
      <table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX2SfMWA3mIjcL_y6D_rPDZQ1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_CategoriesTreeViewn0CheckBox" id="ctl00_Body_CategoriesTreeViewn0CheckBox" title="Prayer" /><a class="ctl00_Body_CategoriesTreeView_0" href="javascript:__doPostBack('ctl00$Body$CategoriesTreeView','s1')" onclick="TreeView_SelectNode(ctl00_Body_CategoriesTreeView_Data, this,'ctl00_Body_CategoriesTreeViewt0');" id="ctl00_Body_CategoriesTreeViewt0">Prayer</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><a id="ctl00_Body_CategoriesTreeViewn1" href="javascript:TreeView_ToggleNode(ctl00_Body_CategoriesTreeView_Data,1,ctl00_Body_CategoriesTreeViewn1,'t',ctl00_Body_CategoriesTreeViewn1Nodes)"><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzXwJx33l_NPW57t40m7ht-9kLit0N6NM4XuHy2GC36lIn0&amp;t=632883495870637959" alt="Collapse Volunteer" style="border-width:0;" /></a></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_CategoriesTreeViewn1CheckBox" id="ctl00_Body_CategoriesTreeViewn1CheckBox" checked="checked" title="Volunteer" /><a class="ctl00_Body_CategoriesTreeView_0" href="javascript:__doPostBack('ctl00$Body$CategoriesTreeView','s2')" onclick="TreeView_SelectNode(ctl00_Body_CategoriesTreeView_Data, this,'ctl00_Body_CategoriesTreeViewt1');" id="ctl00_Body_CategoriesTreeViewt1">Volunteer</a></td>
            </tr>
      </table><div id="ctl00_Body_CategoriesTreeViewn1Nodes" style="display:block;">
            <table cellpadding="0" cellspacing="0" style="border-width:0;">
                  <tr>
                        <td><div style="width:20px;height:1px"><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzXwq8Ng0NpL3MLUVHpxHvn5E1&amp;t=632883495870637959" alt="" /></div></td><td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX-EvRUG_TP5UCG1aTnSOUWY1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_CategoriesTreeViewn2CheckBox" id="ctl00_Body_CategoriesTreeViewn2CheckBox" title="Volunteer SubCat 1" /><a class="ctl00_Body_CategoriesTreeView_0" href="javascript:__doPostBack('ctl00$Body$CategoriesTreeView','s2\\6')" onclick="TreeView_SelectNode(ctl00_Body_CategoriesTreeView_Data, this,'ctl00_Body_CategoriesTreeViewt2');" id="ctl00_Body_CategoriesTreeViewt2">Volunteer SubCat 1</a></td>
                  </tr>
            </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
                  <tr>
                        <td><div style="width:20px;height:1px"><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzXwq8Ng0NpL3MLUVHpxHvn5E1&amp;t=632883495870637959" alt="" /></div></td><td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX4iascjIf74mJB0-PvYVJWk1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_CategoriesTreeViewn3CheckBox" id="ctl00_Body_CategoriesTreeViewn3CheckBox" title="Volunteer SubCat 2" /><a class="ctl00_Body_CategoriesTreeView_0" href="javascript:__doPostBack('ctl00$Body$CategoriesTreeView','s2\\7')" onclick="TreeView_SelectNode(ctl00_Body_CategoriesTreeView_Data, this,'ctl00_Body_CategoriesTreeViewt3');" id="ctl00_Body_CategoriesTreeViewt3">Volunteer SubCat 2</a></td>
                  </tr>
            </table>
      </div><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX-EvRUG_TP5UCG1aTnSOUWY1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_CategoriesTreeViewn4CheckBox" id="ctl00_Body_CategoriesTreeViewn4CheckBox" title="Advocating" /><a class="ctl00_Body_CategoriesTreeView_0" href="javascript:__doPostBack('ctl00$Body$CategoriesTreeView','s3')" onclick="TreeView_SelectNode(ctl00_Body_CategoriesTreeView_Data, this,'ctl00_Body_CategoriesTreeViewt4');" id="ctl00_Body_CategoriesTreeViewt4">Advocating</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX-EvRUG_TP5UCG1aTnSOUWY1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_CategoriesTreeViewn5CheckBox" id="ctl00_Body_CategoriesTreeViewn5CheckBox" title="Giving" /><a class="ctl00_Body_CategoriesTreeView_0" href="javascript:__doPostBack('ctl00$Body$CategoriesTreeView','s4')" onclick="TreeView_SelectNode(ctl00_Body_CategoriesTreeView_Data, this,'ctl00_Body_CategoriesTreeViewt5');" id="ctl00_Body_CategoriesTreeViewt5">Giving</a></td>
            </tr>
      </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
            <tr>
                  <td><img src="/WebResource.axd?d=f8jlEUJvtIzQgBusQxIzX4iascjIf74mJB0-PvYVJWk1&amp;t=632883495870637959" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="ctl00_Body_CategoriesTreeViewn6CheckBox" id="ctl00_Body_CategoriesTreeViewn6CheckBox" title="Serving" /><a class="ctl00_Body_CategoriesTreeView_0" href="javascript:__doPostBack('ctl00$Body$CategoriesTreeView','s5')" onclick="TreeView_SelectNode(ctl00_Body_CategoriesTreeView_Data, this,'ctl00_Body_CategoriesTreeViewt6');" id="ctl00_Body_CategoriesTreeViewt6">Serving</a></td>
            </tr>
      </table>
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 2000 total points
ID: 17168645
Check this:



<script>
function toggleAll(theBox){
  var theForm = theBox.form;
  var elem = theForm.elements;
  var pref = theBox.name.split("_All")[0];
  for(var i=0;i<elem.length;i++){
    if(elem[i].name.indexOf(pref)==0){
      elem[i].checked = theBox.checked;
    }
  }
}
</script>
<form>
 <table width="350">
                        <tr>
                            <td valign="top">
                                Regions:<br><input type="checkbox" name="ctl00_Body_RegionsTreeview_All" onClick="toggleAll(this)" title="All Regions" /> All</td>
                            <td>Categories:<br><input type="checkbox" name="ctl00_Body_CategoriesTreeView_All" onClick="toggleAll(this)" title="All Categories" /> All</td>
                        </tr>




0
 

Author Comment

by:JeffDrummond
ID: 17178986
Thanks Zvonko!  Works perfectly!
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17179990
You are welcome.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 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