keeztian keeztian - 1 year ago 84
HTML Question

HTML inside TextArea?

So I have this textarea in my website. By default, it has something like this as its contents:

Name : Sample Value
Age : Sample Value
Location : Sample Value

It is editable before the user hits the button and inserts it into the database, although I am not using a rich text editor since it's nothing but a simple text.

Since basic HTML codes are not browser readable inside the textarea tag, I used

to separate lines.

Now my problem is that I am not able to include the HTML code when I'm reading the value of the textarea tag in the server side.

Thus, the value inserted to the database is not HTML formatted as well, and when it is once again fetched into a web browser, it has no format at all.

What alternatives do I have? Thanks.

Answer Source

Not possible using textarea, use contenteditable DIV instead.

<div contenteditable="true"></div>

You can use getters and setter as shown below:

//Get content    
var contents = document.getElementById("divId").innerHTML; 

//Set content
document.getElementById("divId").innerHTML = contents

Here is the browser support for this approach.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download