1

I feed a string to my textarea.

The string contains HTML strings, such as ©, é, etc.

I need these strings to be displayed as such (©, é) and not be turned into © and é respectively.

How would I do it?

1 Answer 1

3

Escape them properly, that is turn & into & in this case.

Though, if you feed them using the .value assignment, your problem is not with textarea and your string is deentitified before getting into javascript variable.

Sign up to request clarification or add additional context in comments.

9 Comments

the problem is that I am then submitting the text inside the textarea. So I would then need to change & back into &?
Err.. That's exactly what I said, no? Also, I've added another sentence to my answer which may be of interest. You do not really provide enough information about what you're doing.
I use PHP to get LONGTEXT from MySQL. Then I echo the string into the textarea. The Textarea is inside a <form>. When the form gets submitted, it posts the content of the textarea into another PHP script, which writes info into the MySQL. The MySQL must have those HTML characters as HTML characters, not their graphic representation.
Then you should <textarea><?=htmlentities($string)?></textarea> instead.
Did you notice you tagged your question javascript, not php? :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.