tags:

views:

77

answers:

4

If I have a textarea block like so...

<textarea name="myTextArea" cols="100" rows="20" readonly=readonly>
.. text area content ...
</textarea>

How can I embed HTML formatted text inside this text block? If I can I had figured the following should work...

<textarea name="myTextArea" cols="100" rows="20" readonly=readonly>
<b>Hello how are you today?</b>
</textarea>

As an example. But that sentence does not show up as bold. Maybe I'm just trying to do something that can't be done?

+2  A: 

You need to make a WYSIWYG Editor instead.

Here's a great one.

gmcalab
+1 Or here: www.ckeditor.com
Pekka
Totally unrelated to the question.
Rob
@Rob how is showing someone how to create a rich text editor unrelated to a question asking how to embed markup in a textarea.
gmcalab
@gmcalab, He didn't want a text editor. He didn't ask about a text editor. He asked how to format text inside a textarea element.
Rob
@Rob Yes we can read, but what's the question here? They want an input, that allows markup, so formatting is applied like a rich text editor. Since this matches the functionality of a rich text editor, couldn't that be a possible solution to the question. I know this is way out there, Rob stay with me, though. You got a better answer Rob? Well, if so it's not on here?
gmcalab
@gmcalab, Let's put it this way. You are OT. If you want to start a thread on editors, start your own topic, but others properly answered his question.
Rob
@Rob, interesting since my answer has the highest up-vote. Looks like your in the minority.
gmcalab
+1  A: 

I am pretty sure the answer is no -- cannot do it with a textarea.

MJB
A: 

Nope! If you validated that in an HTML document, you'd get an error along the lines of "document type does not allow element "b" here".

What you might be looking for is a What-You-See-Is-What-You-Get editor, which is actually an <iframe> which is making use of a JavaScript feature designMode. It's possible to find tutorials on how to create these, but it's a much, much better idea to use an existing one, as for it to be really useful and usable takes a lot of work.

Take note that - if you were still interested in validation, which you should be if you're working with HTML - is that you won't be able to use a strict DOCTYPE declaration, as the WYSIWYG editor will be using an iframe.

LeguRi
A: 

You can do this (convert the "special" characters):

<textarea name="myTextArea" cols="100" rows="20" readonly=readonly>
&lt;b&gt;Hello how are you today?&lt;/b&gt;
</textarea>
37Stars
You can do that but it won't show up bold.
gmcalab
Yeh that doesn't work for me. Thanks for the suggestion though.
Rob Segal
Ah, I misunderstood your question then. I thought you wanted to see the HTML tags.
37Stars