Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #14319
| Message-ID | <1974460.6kujNgKlnh@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2012-06-04 14:31 +0200 |
| Subject | Re: Change textarea readonly state |
| Newsgroups | comp.infosystems.www.authoring.stylesheets, comp.lang.javascript |
| References | <4fcb2a24$0$6931$e4fe514c@news2.news.xs4all.nl> <dorayme-F2080F.20040603062012@news.albasani.net> <4fcb3edc$0$6983$e4fe514c@news2.news.xs4all.nl> <jqfjba$laj$1@dont-email.me> <4fcb69d1$0$6923$e4fe514c@news2.news.xs4all.nl> |
| Followup-To | comp.lang.javascript |
Cross-posted to 2 groups.
Followups directed to: comp.lang.javascript
Tom de Neef wrote:
> "Jukka K. Korpela" <jkorpela@cs.tut.fi> schreef:
>> But to save comp.lang.javascript from a confusing thread about a simple
>> matter,
I strongly suggest you heed that old wisdom, "Cobbler, stick to thy last.",
and do not try to force an off-topic discussion (in matters obviously beyond
your competence).
>> here's what you really wanted to ask, and the correct answer:
No.
>> Q: In JavaScript, how can I make a readonly field (one with the readonly
>> attribute) writeable?
>>
>> A: You need to remove the attribute. Changing its value won't help, since
>> its the very presence of the readonly attribute, not its value, that
>> matters. Example:
>>
>> <textarea id="ta" name=ta readonly rows="5" cols="5">Hello</textarea>
>> <input type=button value="Allow write" onclick=
>> "document.getElementById('ta').removeAttribute('readonly')">
Of course, for various good reasons there should not be newline after the
`='.
> Very good. The ability to interpret an unclear question is worth more than
> the ability to answer the question. And you did both.
It is _not_ necessary to remove the attribute and risk calling the error-
prone removeAttribute() method here. The element object has a `readOnly'
attribute *property*:
<input type=button value="Allow write"
onclick="document.getElementById('ta').readOnly = false">
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-24874179>
That said, it is usually a bad idea to set the `readonly' *attribute* in the
first place because it can only be reset with client-side DOM scripting or
by a round trip to the server.
You also want to consider using the `forms' and `elements' collections
instead of making excessive use of document.getElementById(). The least you
should do is to cache the return value of the latter.
X-Post & F'up2 comp.lang.javascript
PointedEars
--
When all you know is jQuery, every problem looks $(olvable).
Back to comp.lang.javascript | Previous | Next | Find similar | Unroll thread
Re: Change textarea readonly state Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-06-04 14:31 +0200
csiph-web