Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #14319

Re: Change textarea readonly state

Path csiph.com!usenet.pasdenom.info!news.albasani.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="ISO-8859-1"
Message-ID <1974460.6kujNgKlnh@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <dciwam@PointedEars.de>
Organization PointedEars Software (PES)
Date Mon, 04 Jun 2012 14:31:50 +0200
User-Agent KNode/4.4.11
Content-Transfer-Encoding 7Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
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
MIME-Version 1.0
Lines 54
NNTP-Posting-Date 04 Jun 2012 14:31:50 CEST
NNTP-Posting-Host 2f6901cf.newsspool3.arcor-online.net
X-Trace DXC=M<[iM6dAlFTHigV@eW57PQMcF=Q^Z^V3X4Fo<]lROoRQ8kF<OcfhCO[o;k`8g]<bOWDZm8W4\YJN\UFDj8T]K0?SDmniOZG;K0[oUO][>RZnhU
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.infosystems.www.authoring.stylesheets:3046 comp.lang.javascript:14319

Cross-posted to 2 groups.

Followups directed to: comp.lang.javascript

Show key headers only | View raw


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


Thread

Re: Change textarea readonly state Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-06-04 14:31 +0200

csiph-web