Change textarea readonly state

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
To make a textarea readonly, I can use
  <textarea readonly="readonly">.. </textarea>

But how to change the state to editable?
Whatever string I use for the attribute value (empty, "no", "false"), the
element remains readonly.
Only thing that works is to remove the attribute altogether but how can I do
that (CSS or javascript)?

Re: Change textarea readonly state

On Sun, 03 Jun 2012 09:44:42 +0200, Tom de Neef wrote:

Quoted text here. Click to load it

In Javascript, set the attribute to false (the value, not the string),

docuemnt.getElementById(textarea_id).readOnly = false;

In html, leave out the readonly attribute from the element:

<textarea cols="40" rows="5"></textarea>

In html 4, the "readonly" attribute is either present or absent, but in
xhtml attributes that are present must have values, so the following is
valid html 4 (and draft html 5) but not valid xhtml

<textarea readonly cols="40" rows="5"></textarea>

So in xhtml, all of the following:

<textarea readonly="0" cols="40" rows="5"></textarea>
<textarea readonly="1" cols="40" rows="5"></textarea>
<textarea readonly="true" cols="40" rows="5"></textarea>
<textarea readonly="false" cols="40" rows="5"></textarea>
<textarea readonly="yes" cols="40" rows="5"></textarea>
<textarea readonly="no" cols="40" rows="5"></textarea>
<textarea readonly="readonly" cols="40" rows="5"></textarea>

all mean the same thing, namely that the readonly attribute is present,
rather than that the readonly attribute has a specific value.


Denis McMahon

Re: Change textarea readonly state

Denis McMahon wrote:

Quoted text here. Click to load it

On the contrary.  Rather unsurprisingly, only the last line is Valid XHTML,
as the sole value of the XHTML `readonly' attribute is "readonly".

< -

var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
)  // Plone, register_function.js:16

Site Timeline