Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 22, 2013 03:27 PM by Ruchira
Member
96 Points
159 Posts
Jan 21, 2013 10:45 PM|LINK
Hi all
I'm having a problem trying to set the readOnly property of a TextBox from Javascript. My HTML code is:
<asp:TextBox ID="txtNoControl" runat="server" Width="40" CssClass="small" ReadOnly="true"></asp:TextBox>
And my JS code:
document.form1.txtNoControl.setAttribute("readOnly", false); document.form1.txtNoControl.removeAttribute("readOnly"); document.form1.txtNoControl.readOnly = false;
None of the JS codes seem to work for me :-( I've google it and in most of the pages those lines of codes are mentioned. However, for me is not working. I'm using IE 7
Is there any wrong in the code? what would be a solution for this?
I appreciate your help
Regards!
Contributor
4065 Points
738 Posts
Jan 21, 2013 11:31 PM|LINK
you are on the right track. Here you go using jQuery
http://jsbin.com/efiley/1/
and then with JS Method added
document.getElementById('txtTest').setAttribute('readonly', true);
http://jsbin.com/efiley/2/
Star
14396 Points
2449 Posts
Jan 22, 2013 05:13 AM|LINK
Hi, Try like this: document.getElementById("txtNoControl").readonly = false;
All-Star
42975 Points
7025 Posts
MVP
Jan 22, 2013 03:27 PM|LINK
Hello,
Try this,
document.getElementById("<%=txtNoControl.ClientID%>").readOnly = false;
Please 'Mark as Answer' if this post helps you.
Lesthad_mk
Member
96 Points
159 Posts
setting the readOnly Attribute is not working in JS
Jan 21, 2013 10:45 PM|LINK
Hi all
I'm having a problem trying to set the readOnly property of a TextBox from Javascript. My HTML code is:
And my JS code:
document.form1.txtNoControl.setAttribute("readOnly", false); document.form1.txtNoControl.removeAttribute("readOnly"); document.form1.txtNoControl.readOnly = false;None of the JS codes seem to work for me :-( I've google it and in most of the pages those lines of codes are mentioned. However, for me is not working. I'm using IE 7
Is there any wrong in the code? what would be a solution for this?
I appreciate your help
Regards!
rojay12
Contributor
4065 Points
738 Posts
Re: setting the readOnly Attribute is not working in JS
Jan 21, 2013 11:31 PM|LINK
you are on the right track. Here you go using jQuery
http://jsbin.com/efiley/1/
and then with JS Method added
document.getElementById('txtTest').setAttribute('readonly', true);
http://jsbin.com/efiley/2/
Lead Application Developer
raju dasa
Star
14396 Points
2449 Posts
Re: setting the readOnly Attribute is not working in JS
Jan 22, 2013 05:13 AM|LINK
Hi,
Try like this:
document.getElementById("txtNoControl").readonly = false;
rajudasa.blogspot.com || blog@opera
Ruchira
All-Star
42975 Points
7025 Posts
MVP
Re: setting the readOnly Attribute is not working in JS
Jan 22, 2013 03:27 PM|LINK
Hello,
Try this,
document.getElementById("<%=txtNoControl.ClientID%>").readOnly = false;
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.