Click here to Skip to main content
15,902,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please Sir,
Give me Suggest.

How to disable textbox using RadioButtonlist.
Suppose I have Three option in RadioButtonlist 1-Cash 2-Cheque 3-Draft

and I have three textBox Bankname,Chequedate and chequeNo.

if I select Cash

then all three textbox will be disable.
but if case 2 and 3
then all textbox will be enabled.
in JavaScript

Thanks
Ashish
Posted

1 solution

Please check this code
JavaScript
function DisableTextBox() {
            var buttonList = document.getElementById('<%=chkBoxList.ClientID %>');
            var inputs = buttonList.getElementsByTagName("input");
            var txtBox1 = document.getElementById('<%=txtBOX1.ClientID %>');
            var txtBox2 = document.getElementById('<%=txtBOX2.ClientID %>');
            var txtBox3 = document.getElementById('<%=txtBOX3.ClientID %>');
            if (inputs[0].checked) {
                txtBox1.disabled = true;
                txtBox2.disabled = true;
                txtBox3.disabled = true;
            }
            else {
                txtBox1.disabled = false;
                txtBox2.disabled = false;
                txtBox3.disabled = false;
            }
        }


ASP.NET
<asp:radiobuttonlist id="chkBoxList" runat="server" onclick="DisableTextBox(this);" xmlns:asp="#unknown">
   <asp:listitem text="Cash" value="0" />
   <asp:listitem text="Check" value="1" />
   <asp:listitem text="Draft" value="2" />
   </asp:radiobuttonlist>
   <asp:textbox id="txtBOX1" runat="server" xmlns:asp="#unknown" />
   <asp:textbox id="txtBOX2" runat="server" xmlns:asp="#unknown" />
   <asp:textbox id="txtBOX3" runat="server" xmlns:asp="#unknown" />



you can attempt with Jquey too and line of code will be decreased Thanks.
 
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