PDA

View Full Version : disable the text in the textarea


carrera
06-19-2002, 08:50 AM
i have a textarea where terms of agreement is placed. I want the text inside it to be disable if a user tries to change it. Can you help me?Tnx

Zvona
06-19-2002, 09:03 AM
either
<textarea ... readonly="readonly"></textarea>
and/or :
<textarea ... disabled="true"></textarea>

I prefer readonly -attribute, which just prevents modifying. Disabled attribute makes the whole area look disabled (grey) and disabled textarea's data isn't submitted, when a form is posted.

requestcode
06-19-2002, 01:57 PM
You might want to use the onFocus event to remove focus so that is also works in NS4.

onFocus="this.blur()"

This will work in both IE and NS whereas the readonly property only works with IE and I believe NS6.

jkd
06-19-2002, 07:38 PM
Actually, last I heard there was a known bug in which onfocus="this.blur()" does NOT work for Gecko browsers (NS6 included). It may have been fixed for Mozilla 1.0 though, and is worth further testing if I get around to it.

Use a combination of:

<textarea readonly="readonly" onfocus="this.blur()">

For best results. :)

glenngv
06-20-2002, 03:08 AM
but you can still right-click inside the textarea and it will not trigger onfocus event, so the user can do right-click & paste.
so you must use this combination:

<textarea readonly="readonly" onfocus="this.blur()" onchange="this.value='blah blah'">blah blah</textarea>

to ensure best results :)


Originally posted by jkd
Actually, last I heard there was a known bug in which onfocus="this.blur()" does NOT work for Gecko browsers (NS6 included). It may have been fixed for Mozilla 1.0 though, and is worth further testing if I get around to it.

Use a combination of:

<textarea readonly="readonly" onfocus="this.blur()">

For best results. :) :thumbsup:

whammy
06-20-2002, 06:46 PM
Can't you also do

onchange="this.value=this.default.value"

?

JohnKrutsch
06-20-2002, 07:40 PM
Originally posted by whammy
Can't you also do

onchange="this.value=this.default.value"

?

Did you try it? It throws up errors when I try it.

whammy
06-20-2002, 11:41 PM
Hmm... you're right. I hadn't tried it... I could *swear* I read about that somewhere - must have dreamed it, LOL

whammy
06-20-2002, 11:47 PM
I just had the wrong syntax:

<form>
<textarea name="blah" rows=8" cols="50" onchange="this.value=this.defaultValue">asdf</textarea>
</form>

works!

:)