Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I want to change visibility of a server control on selection of dropdown value accordingly using java script.

Please help me..
Posted

Hi
Try this code sample....



XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        var change = function (ddl) {
            var value = ddl.value;
            var btn = document.getElementById('btn');
            var chk = document.getElementById('chk');
            var lbl = document.getElementById('lbl');
            var rdb = document.getElementById('rdb');


            if (value == 'button')
                btn.style.visibility = 'hidden';
            if (value == 'checkbox')
                chk.style.visibility = 'hidden';
            if (value == 'label')
                lbl.style.visibility = 'hidden';
            if (value == 'radiobutton')
                rdb.style.visibility = 'hidden';
            if (value == 'All') {
                btn.style.visibility = 'visible';
                chk.style.visibility = 'visible';
                lbl.style.visibility = 'visible';
                rdb.style.visibility = 'visible';
            }
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        visibility ::
        <asp:DropDownList onchange="change(this)" ID="ddl" runat="server">
            <asp:ListItem Text="All" />
            <asp:ListItem Text="button" />
            <asp:ListItem Text="checkbox" />
            <asp:ListItem Text="label" />
            <asp:ListItem Text="radiobutton" />
        </asp:DropDownList>
        <br />
        <br />
        <asp:CheckBox ID="chk" runat="server" Text="" /><br />
        <br />
        <asp:Button ID="btn" runat="server" Text="button" /><br />
        <br />
        <asp:Label ID="lbl" runat="server" Text="label" /><br />
        <br />
        <asp:RadioButton ID="rdb" runat="server" Text="" />
        <br />
    </div>
    </form>
</body>
</html>
 
Share this answer
 
Write this code in .cs file on page load

ddlName.Attributes.Add("onchange", "HideSearchResults();");

javascript code :


C#
function HideSearchResults()
    {
       //write your code here base on codition hide the sercer controls
       //eg. $('.myControl').hide();
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900