How to display a textarea as HTML code inside another textarea?

textarea fixed size
allow html tags in textarea
input type textarea
html tags within textarea
show html code in textarea php
html editable text area
display html code in html
textarea html inside value

I'm developing JSP/Servlet website. I have a form in my JSP page that call Servlet which do some processing then froward the results back to the Same JSP page. The form has textarea that get HTML code from the user and I use syntax highlighting tool for the textarea to format the code inside the textarea.

The problem is when I retain the value of textarea after updating the page, if it the entered code contains a textarea element it render the closing tag of nested textarea as the closing tag of the parent textarea. I retain the value in this way:

<textarea rows="30" cols="80" id="txtArea" name="txtArea" 
placeholder="Enter your code" >${param.txtArea}</textarea>

Here is examples for what is happened:

if user enter this in the textarea everything is retained correctly:

    <form >
        <label for="name">Your name:</label><br />
        <input id="name" type="text" />
        <input id="submit_button" type="submit" value="Send email" />
</form>

However, if the user enter this:

<form >
            <label for="name">Your name:</label><br />
            <input id="name" type="text" />
            <textarea id="message" class="input" name="message" rows="7" cols="30"></textarea>
            <input id="submit_button" type="submit" value="Send email" />
    </form>

it will retain just these line :

<label for="name">Your name:</label><br />
            <input id="name" type="text" />
            <textarea id="message" class="input" name="message" rows="7" cols="30">

Closing textarea tag and everything after that is not retained inside textarea. and render as HTML code. Could anyone help me to find a way to retain all content entered by the user? or how to escape the first closing tag of textarea?

I recommend you to use javascript to assign the desired values to your text area elements. See example below.

Keep in mind that you may need to escaped quotes. You can handle it in java or javascript. Still, javascript is going to be easier to handle what you want comparable to working with java/jsp place holders.

Here is an example to handle it in javascript.

<!DOCTYPE html>
<html><body>

<textarea id="outerArea" cols=50 rows=10></textarea>

<script type="text/javascript">
    var textAreaValue = '<form>'
        +'  <input type="text"><br>'
        +'  <textarea>Inner Text Area</textarea>'
        +'</form>';
    document.getElementById("outerArea").value = textAreaValue;
</script>

</body>
</html>

EDIT Answering OP's comment: Javscript still the way to go. Work with JSP and Javascript variables.

<!DOCTYPE html>
<html>
<header>
<script type="text/javascript">
    function copyContent() {
        document.getElementById("area1").value = ${param.txtArea};
    }
</script>
</header>
<body>
<textarea id="area1" cols=50 rows=10></textarea>
</body>
</html>

How do we display a text area in HTML?, , then it's content cannot be changed but can be copied and highlighted. It is a boolean attribute. Note for people new to this: Always remember whenever you do something like this, if you are getting the HTML string from a user, they can choose any string they want, which might break your own HTML (especially if you save the string on a server, and so allow the user to choose arbitrary code that runs on other people's browsers, this can be a security risk).

If you put the HTML into the textarea tag's value attribute, it's will work correctly.

Like that:

<textarea value="<!DOCTYPE html>
<html>
    <head>
        <title>
            Example page
        </title>
    </head>
    <body>
        <textarea></textarea>
    </body>
</html>"></textarea>

HTML textarea Tag, Is there anyway to show it with the HTML formatting. I am pulling a terms and conditions page from my DB and showing it in a textarea. give us your code and some database info first, we need something to see off of it,  Just remember that it is going to display as text in the textarea. If you want the HTML to be processed as HTML it can't go in a textarea. Hmmmm, I am sure I have seen this done before, like in

i just surrund my textarea with tag then use wyswyg plugin from jquery if you need to show the design out put.

<script src="jquery.richtext.js"></script>
<textarea value="<!DOCTYPE html>
<html>
    <head>
        <title>
            Example page
        </title>
    </head>
    <body>
        <textarea>
        <code>
        some html code here with style<h1>text</h1>
        or any
        </code>
        
        
        </textarea>
    </body>
</html>"></textarea>

HTML5 Textarea Attributes: Here's What You Should Know », The <textarea> tag defines a multi-line text input control. A text area can hold an unlimited number of characters, and the text renders in a fixed-width font  My textarea has a value, but it is not displayed in the textarea, which is working in my input field marked as duplicate by Quentin html Users with the html badge can single-handedly close html questions as duplicates and reopen them as needed.

HTML, The Textarea object also supports the standard properties and events. Related Pages. HTML tutorial: HTML Forms. HTML reference: HTML <textarea> tag · ❮  Click on link next link should be display on same page. javascript,php,jquery,html,css3. Ok, so i tried to decypher what you meant with your Question. To Clarify: He has this one page setup. inside the div Our Project, there are two Buttons or links Visit more. When clicked, he wants the About Section to be shown. All in all it is impossible for

Show HTML in a textarea - HTML & CSS, HTML <textarea> tag. Example. The text in a text area with wrap="hard" will contain newlines (if any) when submitted in a form: <textarea rows="2" cols="20"​  This page contains HTML textarea code — code for creating a textarea on an HTML document. A textarea is a form element that allows the user to enter multiple lines of text. A textarea is created with the HTML <textarea> tag. The textarea can be nested inside a <form> element or it can stand alone. It can also be associated with a form via its form attribute. Basic Textarea Example. Here's an example of an HTML textarea:

HTML textarea tag, For more information, see the autocomplete attribute in <form> . autofocus: This Boolean attribute lets you specify that a form control  Specifies that the text direction of the textarea will be submitted: disabled: disabled: Specifies that a text area should be disabled: form: form_id: Specifies which form the text area belongs to: maxlength: number: Specifies the maximum number of characters allowed in the text area: name: text: Specifies a name for a text area: placeholder: text

Comments
  • I could not use this. I just have 1 textarea in my code in JSP page. The user will enter his html code in that textarea. If the user code does not contain textarea that will be fine and there is no any problems. However, if the user code has a textarea in it here we will have the problem. So, I can't know if the textarea will contain another one or not.
  • I want to display for user exactly what he/she enter.
  • Still, if you use JSP Place Holders you will run into many other problems. Add the content o the place holder to a javascript variable and assign it to your text area.
  • This is not work the textarea is empty after submitting the form. Also, it shows an error in console if I use ${param.txtArea} inside javascript.