How do I enable HTML for textareas? Do I need to get some kind of text editor or can I just enable it? I need help with this. I'm making user-written game walkthroughs and they want HTML enabled so they can add images, videos, etc.
So, how do I?
How do I enable HTML for textareas? Do I need to get some kind of text editor or can I just enable it? I need help with this. I'm making user-written game walkthroughs and they want HTML enabled so they can add images, videos, etc.
So, how do I?
You're going about this the wrong way. When typing into a textarea
, the information being entered is literally just strings of characters. I could type the following:
<h1>Hello, World!</h1> Here is some text <br/> Here is some more <ul><li>This is a list</li></ul>
But the browser treats it as simply a sequence of characters, no more than if you were to just type this:
The quick brown fox jumps over the lazy dog
.
If you're trying to get hand-written HTML parsed and displayed as code, then you need to use some Javascript that reads the contents of the text and puts it into an empty div
or some other element that is meant to be filled with code
instead of text
.
An example with jQuery:
<textarea id="inputBox">
type some HTML inside me
</textarea>
<div id="resultsBox"></div>
<script>
$('#inputBox').on('input',function() {
$('#resultsBox').html($('#inputBox').val());
});
</script>
This code listens for when the user types something into the textarea
and inserts that data as HTML into the div
.
The point is that you can't have text in a textarea 'turn into' HTML without somewhow loading it into a non-text-input element. Until you do that, the entered data is simply a string.
Note that even invalid and unfinished HTML will be inserted in this example.