This article will show you how you can enable disable
textbox using jascript radio button click in asp.net radbutton.
So for this article first we will create a new asp.net
application and add some radiobutton and a textbox control on page. After
adding controls your code will look as shown below.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RedioButton.aspx.cs" Inherits="Shoping_Cart.RedioButton" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Enable Disable
Textbox Using Jascript Radio Button Click</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Width="228px"></asp:TextBox>
<br />
<br />
<asp:RadioButton ID="rbtEnable"
runat="server" Text="Enable" />
<asp:RadioButton ID="rbtDisable"
runat="server" Text="Disable" />
</div>
</form>
</body>
</html>
|
Now let’s write code for enabling and disabling the textbox.
function
EnableDisableTextBox() {
var status =
document.getElementById('<%=rbtEnable.ClientID %>').checked;
if (status == true) {
document.getElementById('<%=TextBox1.ClientID %>').disabled = false;
} else {
document.getElementById('<%=TextBox1.ClientID %>').disabled = true;
}
}
|
In above code I have get the checked status of the radio button and then on status I have enable disable the textbox on click on radio button selection.
Here is the complete code.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RedioButton.aspx.cs" Inherits="Shoping_Cart.RedioButton" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Enable Disable
Textbox Using Jascript Radio Button Click</title>
<script type="text/javascript">
function
EnableDisableTextBox() {
var status =
document.getElementById('<%=rbtEnable.ClientID %>').checked;
if (status == true) {
document.getElementById('<%=TextBox1.ClientID %>').disabled = false;
} else {
document.getElementById('<%=TextBox1.ClientID %>').disabled = true;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Width="228px"></asp:TextBox>
<br />
<br />
<asp:RadioButton ID="rbtEnable"
runat="server" Text="Enable" onclick="javascript:EnableDisableTextBox();" GroupName="1" />
<asp:RadioButton ID="rbtDisable"
runat="server" Text="Disable" onclick="javascript:EnableDisableTextBox();" GroupName="1" />
</div>
</form>
</body>
</html>
|
0 comments:
Please let me know your view