Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am having two radio buttons and two textbox. When I click on first checkbox, both texbox should not be readonly. But when I select second radio button it should make both text box readonly. I googled and found many solutions but don't kno why it is not working in my code.

My code is as follows:

ASP.NET
<asp:RadioButton ID="mailNew" Text="New" runat="server" GroupName="mail_select" onclick="showHide(1)" ClientIDMode="Static" /><br />
        
<asp:RadioButton ID="mailExisting" Text="Existing" runat="server" GroupName="mail_select" onclick="showHide(1)" ClientIDMode="Static" />

<asp:TextBox ID="txtPromotion" runat="server" Width="77px" ></asp:TextBox><br />
<asp:TextBox ID="txtSubject" runat="server" Width="288px"></asp:TextBox>

Javascript:
JavaScript
<script type="text/javascript">
        function showHide(val) {
            var txtpid=document.getElementById(<% = txtPromotion %>)
            var txtsub=document.getElementById(<% = txtSubject %>)
            if (val == 2) {
                txtpid.readOnly = false;
                txtsub.readOnly=false;
            }
            if (val == 1) {
                txtpid.setAttribute("readOnly,true");
                txtpid.setAttribute("readOnly.true");
            }
        }
Posted
Comments
[no name] 10-Feb-14 6:45am    
for making text box readonly
try document.getElementById('textbox-id').readOnly=true
or
textbox-id.Attributes.Add("readonly","readonly")
Kornfeld Eliyahu Peter 10-Feb-14 6:51am    
You may complete your code...it can be of help.

 
Share this answer
 
 
Share this answer
 
Comments
Ami_Modi 10-Feb-14 7:38am    
I have only posted the answer in the link above
Kornfeld Eliyahu Peter 10-Feb-14 7:42am    
It not too welcome to post the same question twice...
Not a good behavior...
Ami_Modi 10-Feb-14 7:44am    
Actually it happened by mistake. Sorry for that.
Kornfeld Eliyahu Peter 10-Feb-14 7:54am    
You have been condoned my son!
Ami_Modi 10-Feb-14 22:43pm    
I didn't get whole question here. So I edited and don't know what happened it became another question. I didn't do it intentionally.
C#
function showHide(val) {
    var txtpid=document.getElementById('<% = txtPromotion.ClientID %>')
    var txtsub= document.getElementById('<% = txtSubject.ClientID %>');
    if (val == 2) {
        txtpid.readOnly = false;
        txtsub.readOnly = false;
    }
    else if (val == 1) {
        txtsub.readOnly = true;
        txtpid.readOnly = true;
    }
}


This solved my problem
 
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