How to make TextArea Uneditable?

They have: 24 posts

Joined: May 1999

Hi, I wish to know is there any way that i can make a textarea on a html page uneditable .

thank you

They have: 48 posts

Joined: Dec 1999

I don't think that this is possible, isn't the whole point of a textarea box so you can edit it?

------------------
Do you want to have fun?
TomWorld

Do you want to have fun?
TomWorld

They have: 850 posts

Joined: Jul 1999

Tom Knight, not in some cases. I know I have a script where I would rather have the textbox uneditable.

For instance, if a site had a textarea that had html code to link to there site, it would be better if the textarea was uneditable.

Anyhow, Lynn, if you find an answer for this somewhere else, it would be great if you could post the code here.
Thanks.

------------------
Elephants are the only mammals that can't jump.

They have: 8 posts

Joined: Jan 2000

That's a very useful application of a textarea but the original intent was for use in a form, right?

Just commenting, not offering help or something useful like that.

------------------
jinkies

jinkies

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

You can use this:

<textarea onfocus="blur()">Yourstuff</textarea>;

But I'm not quite sure this is what you want.

Jack

They have: 48 posts

Joined: Dec 1999

robp, I suppose you've got a point

------------------
Do you want to have fun?
TomWorld

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi,

At my site I a Locked Fields script that demonstrates 2 ways of disabling edits (neither one uses MS's proprietary property for locking) One uses an onmouseover=alert; the other. onfocus http://members.aol.com/grassblad

------------------

Where the world once stood
the blades of grass cut me still

They have: 48 posts

Joined: Dec 1999

Another way of doing it, is to have the text in the textarea box to refresh itself every second. Put the following script in the head section

code:

<script language="JavaScript">
<!-- hidden
 function noEdit()
  {
   document.formName.dontEditMe.value="This text should be uneditable"

   setTimeout('noEdit()',1000)
  }
//-->
</script>
[/code]

Then in the body section:

code:
<form name="formName">
<textarea rows="10" cols="60" name="dontEditMe"></textarea>
</form>
<script language="JavaScript">
<!--
noEdit();
//-->
</script>[/code]



------------------
Do you want to have fun?
TomWorld 

Do you want to have fun?
TomWorld

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi,

The refresh probably would work (never tried it, though) but it would screw up any of the other variables and already clicked-on elements on the page.
Then again, that does give new meaning to maintaining state.

Vinny http://members.aol.com/grassblad

Where the world once stood
the blades of grass cut me still

They have: 48 posts

Joined: Dec 1999

The refresh works by only refreshing what is in the textarea box, it doesn't refresh the entire page, so any other variables would be fine.

------------------
Do you want to have fun?
TomWorld

Do you want to have fun?
TomWorld

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Sorry Tom Sad

hate wearing glasses to read from screen, so I never read the code (too small for my eyes).

Vinny http://members.aol.com/grassblad

They have: 2,390 posts

Joined: Nov 1998

...or just put disable in the input tag
(works in IE only)

code:

<input name="form" disable>[/code]
JP 
Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

Yes, but with 'disabled' in the tag everything turns gray. And I think some people might not want that to happen.

Jack

They have: 2,390 posts

Joined: Nov 1998

true, in that case the onFocus is your best bet.
JP

They have: 1 posts

Joined: Oct 2008

code:
Yourstuff
[/code]

But I'm not quite sure this is what you want.

Jack

Shakespeare: onclick or not(onclick)

thanks Jack Michaelson!!!...it did help me...more powers!!! GOD BLESS ALWAYS

JeevesBond's picture

He has: 3,955 posts

Joined: Jun 2002

Wow, this is an old topic. Glad it helped you though mydelf.

Welcome to the forums! Smiling

demonhale's picture

He has: 3,281 posts

Joined: May 2005

blast from the past... I wonder where JM is...

Jack Michaelson's picture

He has: 1,733 posts

Joined: Dec 1999

right here Smiling

By the way: Nowadays I wouldn't use a textarea, but making a div look like one.

demonhale's picture

He has: 3,281 posts

Joined: May 2005

There you are, I thought you hid with the cheese... lol!

Yeah I usually use div's too since I can format it better, but you can also apply css styling to textareas to make it appear like div's so it's reversible... lol!

They have: 40 posts

Joined: Aug 2008

You should use java script and style sheet on particular Text box. It will very helpful for you and use blur.

They have: 1 posts

Joined: Oct 2010

Using JavaScript to prevent editing a textfield is a very roundabout way to solve a simple problem because textarea has an attribute called readonly.

Used like this:

<textarea readonly="readonly"></textarea>

They have: 22 posts

Joined: Oct 2010

You can add disabled="true" to , but then its name/value pair won't be submitted when the form is submitted.

Thanks

They have: 5 posts

Joined: Dec 2010

I follow the links that you provide in this thread and also follow that code that is in this thread. I think it is very much useful for my professional upgradeable. This is really very informative thread for me.

They have: 46 posts

Joined: Jan 2011

you can make textarea uneditable by setting the value of the attribute-readonly of the textarea tag as readonly

readonly="readonly"

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.