Thursday, July 31, 2014

Enable / Disable Div controls based on RadioButtonList Using JavaScript

 Enable / Disable Div controls based on Radio buttons 

          RadioButtonList Using JavaScript 



 protected void Page_Load(object sender, EventArgs e)
        {
            radioBtnSelect.Attributes.Add("onClick", "GetRDBValue();");
        }

     ---------------------------------------------------------------------------------------------------------

<!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 id="Head1" runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" language="javascript">
        function GetRDBValue() {
            // debugger;
            var showdiv1 = document.getElementById('Div1');
            var showdiv2 = document.getElementById('Div2');

            var radio = document.getElementsByName('radioBtnSelect');
            //  debugger;
            if (radio.length > 0) {

                if (radio[0].cells[0].children[0].checked ==
           true && radio[0].cells[0].innerText == "One1") {
                    showdiv1.style.display = "none";
                    showdiv2.style.display = "none";
                }
                if (radio[0].cells[1].children[0].checked ==
           true && radio[0].cells[1].innerText == "Two2") {
                    showdiv1.style.display = "block";
                    showdiv2.style.display = "none";
                }

                if (radio[0].cells[2].children[0].checked ==
           true && radio[0].cells[2].innerText == "Three3") {
                    showdiv1.style.display = "block";
                    showdiv2.style.display = "block";
                }
            }
        }
    </script>
</head>


<body>
    <form id="form1" runat="server">
    <asp:RadioButtonList ID="radioBtnSelect" runat="server" RepeatDirection="Horizontal">
        <asp:ListItem Text="One1" Value="1"></asp:ListItem>
        <asp:ListItem Text="Two2" Value="2"></asp:ListItem>
        <asp:ListItem Text="Three3" Value="3"></asp:ListItem>
    </asp:RadioButtonList>


    <div id="checkdiv" style="">
        Hi Welcome check Div</div>
    <div>
        <div id="Div1" style="display: none">
            Hi Welcome Div1</div>
        <div>
            <div id="Div2" style="display: none">
                Hi Welcome Div2</div>
            <div>
            </div>
    </form>
</body>
</html>

No comments:

Post a Comment