How to make a TextArea/Field uneditable?

Is there a way in HTML or in combination with JavaScript to make a TextArea/Field uneditable?

Btw: I am not looking for answers where text is put into HTML directly. It must be with a TextArea/Field.

Regards Jan
LVL 2
e4monschAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oubelkasCommented:
Yes, with disabled set to true :

<html>
<head>
<title> disable things </title>
</head>
<body>
<textarea name="mytextarea" rows="5" cols="50" disabled="true">this is disabled</textarea>
</body>
</html>

J.
0
e4monschAuthor Commented:
Well this works fine in IE, but I also need it for Netscape Communicator 4.x

Regards Jan
0
oubelkasCommented:
Yep, true it only works in IE, because disabled is embedded in dcom, like ActiveX, this is only IE. I don't know a way how to disable text in NS, and I'm most sure this isn't possible.

J.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

knightEknightCommented:
<FORM name='myform'>
<TEXTAREA name='mytextarea' onFocus='setTimeout("document.myform.mytextarea.blur()",1);'>
</textarea>
</form>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
knightEknightCommented:
.. same kind of thing will work with <INPUT type='text'
just make sure you get the form name and the field name correct in the setTimeout.
0
oubelkasCommented:
What you can also do, and this takes less CPU time, so your application runs faster :

<FORM name='myform'>
<TEXTAREA name='mytextarea' onFocus='mytextarea.blur();' > 
disable text
</textarea>

J.

0
knightEknightCommented:
oubelkas,
what you propose will not work cleanly in earlier browsers because the blur event gets fired before the focus event completes, that is why I use the setTimeout.  Besides, the setTimeout only adds one millisecond to the click event, and I'm sure most applications can aford that.

Also, the correct syntax for your method is this:

<TEXTAREA name='mytextarea' onFocus='this.blur();' >
This will not work well in early browsers
</textarea>
0
oubelkasCommented:
Hey knightEknight, no heart feelings man...I ain't competing against you, since you have a lot more experience than I have. But I reckon most users already have the most updated browsers, IE4+ and NS4+. And this.blur() and mytextarea.blur() will have the same output doesn't it?

;-)

J.
0
e4monschAuthor Commented:
Thanks to both of you. It works fine. The last comment about the timeout thing was very interessting.

Regards Jan
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.