I am using asp TreeView control. I want to get selected "checboxes" values at client side. How do I get selected values from TreeView?
3 Answers
Suppose your treeview has id treeviewid
$('#treeviewid input[type=checkbox]:checked').each(function(){
alert($(this).val());
});
4 Comments
Chirag Khatsuriya
I am getting "On" as output. I want value of checkbox which is binding while creating treeview. tn.ChildNodes.Add(new TreeNode(Sector.SectorName, Sector.SectorId.ToString())); @
Adil
You can use attr to get the attributes e.g. you want to get attribute name, alert($(this).attr('name'));
Chirag Khatsuriya
adil-> I want SectorID , but when I see in source view I can't find it.
Adil
Check it might be given to some other html element, if you can find it in source then we can access it. If it is not source then it is impossible to get it.
I think you should use clientId
$('#<%=MyTreeView.ClientID%>').find(':checkbox:checked').each(function(){
console.log($(this).val());
});
1 Comment
Michael Malinovskij
Yes, but .find selector doesn't need "input" and should look like .find(':checkbox:checked').
I've used the following code to determine all the checked checkboxes:
$("input:checkbox").each(function () {
if ($(this).is(':checked')) {
//do something
}
}
1 Comment
Resource
So simple, so nice.