Click here to Skip to main content
15,920,956 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I set my three textbox enabled=false in asp and I want to change their enabled = true
when one of my three radio button checked.but it does not work


JavaScript
<head  runat="server">
<script language="javascript" type="text/javascript">


 function Radio1_onclick() {

            document.getElementById('TextBox1').Enabled = true;
        }

 function Radio2_onclick() {
            document.getElementById('TextBox2').Enabled = true;
        }

 function Radio3_onclick() {
            document.getElementById('TextBox1').Enabled = true;
            document.getElementById('TextBox2').Enabled = true;
        }

</script>

</head>


HTML
<body>
    <form id="form1" runat="server">
<div>

<table>

<tr>
  <td class="style1">  
     <asp:Label ID="Label1" runat="server" Text="شماره dsl :">    <asp:TextBox ID="TextBox1"  runat="server" Enabled="False"></td>
  <td class="style2"> 
<asp:Label ID="Label2" runat="server" Text="کد کاربری :"> <asp:TextBox ID="TextBox2" runat="server" Enabled="False"></td>
               
 </tr>


<tr>
<td> <asp:Label ID="Label3" runat="server" Text="DSL :">
            
<input id="Radio1" type="radio" value="rd1" name="val"   önclick="return Radio1_onclick()" /></td>
            
<td> <asp:Label ID="Label4" runat="server" Text="کد کاربری :"> 
            
<input id="Radio2" type="radio" value="rd2" name="val"   önclick="return Radio2_onclick()" /></td>
            
<td> <asp:Label ID="Label5" runat="server" Text="هر دو"> 
            
<input id="Radio3" type="radio" value="rd3" name="val"   önclick="return Radio3_onclick()" /></td>
            </tr>

</table>

</div>
    </form>
</body>
</html>
Posted
Updated 19-Jul-11 5:07am
v5

try use this code:


XML
<script language="javascript" type="text/javascript">

 function Radio1_onclick() {                                                                                
            document.getElementById('<%= TextBox1.ClientID %>').disabled = false;
        }
 function Radio2_onclick() {
            document.getElementById('<%= TextBox2.ClientID %>').disabled = false;
        }
 function Radio3_onclick() {
            document.getElementById('<%= TextBox1.ClientID %>').disabled = false;
            document.getElementById('<%= TextBox2.ClientID %>').disabled = false;
        }                                                                                           
</script>



or this code:


XML
<script language="javascript" type="text/javascript">

function Radio_onclick() {
if(document.getElementById('Radio1').checked){
            document.getElementById('<%= TextBox1.ClientID %>').disabled = false;
        }
else if(document.getElementById('Radio2').checked){
            document.getElementById('<%= TextBox2.ClientID %>').disabled = false;
        }
else if(document.getElementById('Radio3').checked){
            document.getElementById('<%= TextBox1.ClientID %>').disabled = false;
            document.getElementById('<%= TextBox2.ClientID %>').disabled = false;
}                                                                                                             

</script>



call Radio_onclick function all radio button onclick event.
 
Share this answer
 
v2
I guess you have Third text box as "TextBox3" and you want to enable all three textboxes if any radio button is checked.

Write one common Javascript function "EnableTextboxes()" and call it on onClick event of your Radio Buttons.

function EnableTextboxes() 
{
 if(document.getElementById('<%= Radio1 %>').checked || document.getElementById('<%= Radio2 %>').checked ||
document.getElementById('<%= Radio3 %>').checked)
{
 document.getElementById('<%= TextBox1.ClientID %>').disabled = false;
  document.getElementById('<%= TextBox2.ClientID %>').disabled = false;
document.getElementById('<%= TextBox3.ClientID %>').disabled = false;
|

}

<input id="Radio1" type="radio" value="rd1" name="val"   önclick="return EnableTextboxes()" />
                      
<input id="Radio2" type="radio" value="rd2" name="val"   önclick="return EnableTextboxes()" />
                       
<input id="Radio3" type="radio" value="rd3" name="val"   önclick="return EnableTextboxes()" />
 
Share this answer
 
v3

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