Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #14319 > unrolled thread
| Started by | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| First post | 2012-06-04 14:31 +0200 |
| Last post | 2012-06-04 14:31 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.javascript
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Change textarea readonly state Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-06-04 14:31 +0200
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2012-06-04 14:31 +0200 |
| Subject | Re: Change textarea readonly state |
| Message-ID | <1974460.6kujNgKlnh@PointedEars.de> |
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 top | Article view | comp.lang.javascript
csiph-web