Link to home
Start Free TrialLog in
Avatar of e4monsch
e4monsch

asked on

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
Avatar of oubelkas
oubelkas

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.
Avatar of e4monsch

ASKER

Well this works fine in IE, but I also need it for Netscape Communicator 4.x

Regards Jan
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.
ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
.. 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.
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.

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>
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.
Thanks to both of you. It works fine. The last comment about the timeout thing was very interessting.

Regards Jan