0

Hi,

In my ASP.NET page I have a TreeView where ShowCheckBoxes="Leaf".
I want to mark as checked/unchecked all the visible checkboxes by clicking in a button.

My code for selecting all/none nodes is like this:

function selectAllNone(tvID, value) {
            var tvNodes = document.getElementById(tvID);
            var chBoxes = tvNodes.getElementByTagName("input");
            for (var i = 0; i < chBoxes.length; i++) {
                var chk = chkBox[i];
                if (chk.type == "checkbox") {
                    chk.cheked = value;
                }
            }        
        }

However, in the line var chBoxes = tvNodes.getElementByTagName("input");I'm having this error message: object doesn't support this property or method.
How do I checj/uncheck all the checkboxes, then?

Thanks,

Ana

4
Contributors
12
Replies
14
Views
7 Years
Discussion Span
Last Post by ananthat
Featured Replies
1

i think that method is not getElementByTagName, but getElementsByTagName, so it is plural basically. try that way.

0

here you go :

<script language="javascript" type="text/javascript">
// <!CDATA[

function Button1_onclick() {
var inputs = document.forms[0].elements;
for(var i=0;i< inputs.length;i++)
{
inputs[i].checked = true;
}
}

function Button2_onclick() {
var inputs = document.forms[0].elements;
for(var i=0;i< inputs.length;i++)
{
inputs[i].checked = false;
}
}

// ]]>
</script>
0

Just in case you cant run the attachment :
Default.aspx :

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
<script language="javascript" type="text/javascript">
// <!CDATA[

function Button1_onclick() {
var inputs = document.forms[0].elements;
for(var i=0;i< inputs.length;i++)
{
inputs[i].checked = true;
}
}

function Button2_onclick() {
var inputs = document.forms[0].elements;
for(var i=0;i< inputs.length;i++)
{
inputs[i].checked = false;
}
}

// ]]>
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;<input id="Button1" type="button" value="Select All" onclick="Button1_onclick()" />
        <input id="Button2" type="button" value="Deselect All" onclick="return Button2_onclick()" /><br />
        <br />
        <asp:TreeView ID="TreeView1" runat="server" ShowCheckBoxes="All">
            <Nodes>
                <asp:TreeNode Text="New Node" Value="New Node">
                    <asp:TreeNode Text="New Node" Value="New Node"></asp:TreeNode>
                </asp:TreeNode>
                <asp:TreeNode Text="New Node" Value="New Node">
                    <asp:TreeNode Text="New Node" Value="New Node"></asp:TreeNode>
                </asp:TreeNode>
                <asp:TreeNode Text="New Node" Value="New Node">
                    <asp:TreeNode Text="New Node" Value="New Node"></asp:TreeNode>
                </asp:TreeNode>
            </Nodes>
        </asp:TreeView>
        &nbsp;</div>
    </form>
</body>
</html>

Edited by serkan sendur: n/a

0

Hi Serkan,

You were right: the method is getElementsByTagName. I just changed it and it's working.

Thanks =)

0

in the beginning of each post there is a "add to serkan's reputation" link , you basically click on it and then select agree radio button then type something then click ok.

0

Looks simple.
Change
var tvNodes = document.getElementById(tvID);
to
var tvNodes = document.getElementsById(tvID);

Hope It worked.Do tell Us.
Happy Coding.

Hi,

In my ASP.NET page I have a TreeView where ShowCheckBoxes="Leaf".
I want to mark as checked/unchecked all the visible checkboxes by clicking in a button.

My code for selecting all/none nodes is like this:

function selectAllNone(tvID, value) {
            var tvNodes = document.getElementById(tvID);
            var chBoxes = tvNodes.getElementByTagName("input");
            for (var i = 0; i < chBoxes.length; i++) {
                var chk = chkBox[i];
                if (chk.type == "checkbox") {
                    chk.cheked = value;
                }
            }        
        }

However, in the line var chBoxes = tvNodes.getElementByTagName("input");I'm having this error message: object doesn't support this property or method.
How do I checj/uncheck all the checkboxes, then?

Thanks,

Ana

0

Hi,

Just use the below code. The first one have lot of spelling mistakes.

function selectAllNone(value) {
            var tvNodes = document.getElementById("trvMenu");
            var chBoxes = tvNodes.getElementsByTagName("input");
            for (var i = 0; i < chBoxes.length; i++) {
                var chk = chBoxes[i];
                if (chk.type == "checkbox") {
                    chk.checked = value;
                }
            }
            return false;
        }

Thanks and Regards,

Ananth N

Edited by Ezzaral: Added code tags and snipped email address. Read the site rules.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.