Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I embed a textarea inside of another textarea in HTML?

Tags:

html

Is there a way to embed a textarea block inside of another textarea block but not render the inside textarea and preserve the outside textarea? I cannot modify the inside textarea. Perhaps there is something better to use for the outside block than a textarea. I need something that will submit its contents at POST. Converting the inside angle brackets to entities is not an option since I want to preserve the html inside the outer textarea.

Non-working Sample Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>Test Embedded textareas</title>
</head>
<body>
    <form method="POST">
        <textarea>
            Outside Textarea
            <textarea>Inside Textarea</textarea>
        </textarea>
        <input type="submit" value="Submit" />
    </form>
</body>
</html>
like image 512
John Scipione Avatar asked Oct 28 '09 16:10

John Scipione


People also ask

Can I embed HTML formatting inside of a textarea tag?

I am pretty sure the answer is no -- cannot do it with a textarea. From the MDN docs: The HTML <textarea> element represents a multi-line plain-text editing control.

Can I put Div inside textarea?

No, it is not possible(it will not render the UI). If you want to show form fields why are you using textarea ? You can just use normal html. Save this answer.

Is it valid to have a textarea element inside a button?

You shouldn't try to place a button inside a textarea, that's doesn't make sense semantically and shouldn't be done. You could do what you're currently doing: positioning the button on top of the textarea in the right place.

Can textarea be used outside form?

Yes you can use textarea tags outside of a form and they will display and allow text to be inserted and edited, but not being tied to a form their uses will likely be limited.


1 Answers

Yo dawg.

Seriously, encoding the html is the only option. You can always decode it/do whatever in your server-side code once it gets posted.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>Test Embedded textareas</title>
</head>
<body>
    <form method="POST">
        <textarea>
            Outside Textarea
            &lt;textarea&gt;Inside Textarea&lt;/textarea&gt;
        </textarea>
        <input type="submit" value="Submit" />
    </form>
</body>
</html>
like image 193
Chetan S Avatar answered Oct 12 '22 20:10

Chetan S