473,388 Members | 1,215 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

change textbox readonly

nirmalsingh
218 100+
hai all,
in html i have created a text box and make it readonly such as

<input type="text" id="age" readonly/>


now i want to make it enable(through javascript) to type in text box . what should i do for this?
Jun 1 '07 #1
5 47959
dmjpro
2,476 2GB
Expand|Select|Wrap|Line Numbers
  1. obj_ref.readOnly = false;
  2. //or obj_ref.setAttribute("readonly") = false;
  3.  
kind regards.
dmjpro.
Jun 1 '07 #2
gits
5,390 Expert Mod 4TB
Expand|Select|Wrap|Line Numbers
  1. obj_ref.readOnly = false;
  2. //or obj_ref.setAttribute("readonly") = false;
  3.  
kind regards.
dmjpro.
hi ... please excuse me and may be i'm wrong ... but i think that will not work, as far as i know ... most browsers look for existence of the readonly attribute ... and therefore it works without having a value assigned:

[HTML]<input type="text" id="age" readonly/>[/HTML]

so the right way is to remove that attribute from that element, you may use a function like the shown one below:

Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * @param obj - reference to element where attr should be changed (use: 
  3.  * document.getElementById('id') or whatever you want for this)
  4.  * @param - state true or false
  5.  */
  6. function set_readonly_state(obj, state) {
  7.     if (state) {
  8.         obj.setAttribute('readonly', state);
  9.     } else {
  10.         obj.removeAttribute('readonly');
  11.     }
  12. }
kind regards ...
Jun 1 '07 #3
acoder
16,027 Expert Mod 8TB
hi ... please excuse me and may be i'm wrong ... but i think that will not work, as far as i know ...
Yes, it should work, see link. I tried some sample code in Firefox and it works fine.
Jun 1 '07 #4
gits
5,390 Expert Mod 4TB
Yes, it should work, see link. I tried some sample code in Firefox and it works fine.
hmmm ... thats right ... i'm sorry! but using this way is a little bit different from my point of view ... until there is a difference between setting an attribute or using a property of an element. the code i provided, simply uses the readonly attribute of the input-element. I didn't know about the 'readOnly' property of the element and of course this works too ... but i think it is good (coding-)practice to use only one way of setting ui-element-states that means use properties OR use attributes (in case they do the 'same') ... i hope you understand what i'm trying to say? the input-element in our example is set to readonly-state through an attribute ... setAttribute it to false will not work ... you have to remove it to enable the widget.

if you prefer to set properties ... than it works fine too ... of course, but it mixes the possibilities and in larger apps this is hard to debug, or to find ... it's only an idea of me and my personal point of view ... you may agree or disagree with it ... ;)

kind regards ...
Jun 1 '07 #5
acoder
16,027 Expert Mod 8TB
... it's only an idea of me and my personal point of view ... you may agree or disagree with it ... ;)
I don't disagree with what you're saying. I was merely pointing out that the readOnly property does exist.
Jun 4 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: pv_kannan | last post by:
Hello, I am stuck with a problem trying to mimic the behavior of a Windows Forms Readonly textbox in HMTL/ASP.NET. Basically, I would like the text to be readonly and overflow the textbox...
2
by: Tor Inge Rislaa | last post by:
How to change row height in a DataGrid I have DataGrid that is filled with data from a table in a DataSet. The content of the cells is text of more than one line (as a note field). What I...
0
by: Jeff User | last post by:
I have my datagrid running pretty much with a EditCommandColumn and some TemplateColumn columns. There are two types of appearance changes I would like to make programatically from my C# code...
2
by: Eric | last post by:
I have a textbox on a form that is populated from the database when the form loads. When I check textbox.Text when the user clicks my submit button, the value is always what it was when the form...
0
by: Groove | last post by:
I've noticed something that's come up twice today alone. In ASP.NET 1, I could reference and use a control's property if the control was set to readonly or if it was set to visible = false. Such...
3
by: RSH | last post by:
Hi, Is it possible to change the type of controls at run-time? In other words I have a form with TextBoxes etc. on it. If the user only has readonly privelages I was wondering if I could...
6
by: Brandon McCombs | last post by:
Hello, I have a Form that contains some configuration information. One of the settings is for SSL. There is a checkbox that I want to check to make 2 textboxes un-editable so that a user can...
10
by: moondaddy | last post by:
I have a textbox on a webform and based on certain conditions I wanted to prevent a user from editing its text. I dont like the look of the texbox when its disabled and was wondering if there is a...
4
by: Dean Slindee | last post by:
Anyone got a quick and easy way to change the background color on a textbox after the user has change the text value. Already have lots of forms written, so an approach that does not depend on...
10
by: engteng | last post by:
When textbox properties enable = False the font in the textbox become gray color. How do I change the gray color to black color ? Regards, Tee
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.