开发者

How can I embed a textarea inside of another textarea in 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>


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>


I've have adequate success wrapping the textarea in a paragraph tag. These one worked for me:

<p style="margin:0;"><textarea rows="1" readonly="readonly" id="summary" name="Summary" ></textarea></p>

<p><textarea name="Note"></textarea></p>

This one didn't work for me:

<p><textarea rows="4" name="In_Honor_Address" class="blockInput"></textarea></p>

Haven't figured out what the difference is between one of these working and the other not, but worth a try.


No. You can't do it. The only thing valid inside of a textarea is text. It's a textarea. :-)


Why?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>Test Embedded textareas</title>
</head>

<style type="text/css">
    #outside { position:absolute; top:0; left:0; z-index:0; width:400px;
        height:400px }
    #inside  { position:absolute; top:100px; left:100px; z-index:1; 
        width:200px; height:200px; }
</style>

<body>

    <div>

        <textarea id="outside" rows="10" cols="80">
            Outside Textarea
        </textarea>

        <textarea id="inside" rows="5" cols="60" readonly>
            Inside Textarea
        </textarea>

    </div>

</body>
</html>


Heres your solution:

Replace all <'s and >'s with

&lt; and &gt;


Try this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>Test Embedded textareas</title>
</head>
<body>
    <textarea>
        Outside Textarea

    </textarea>
<textarea style="margin-top:-250px; height:250px;">Inside Textarea</textarea>
</body>
</html>


Try a hidden form field.


Have you considered using FckEditor?


I recently had the same issue and after searching high and low over the net for an answer i resolved it by putting the inside form into a seamless iframe.


I actually ran into this, as i edit my templates via a textare on my site I want to of course have a textarea on the site....

My solution, when showing the text in the textarea for editing i do a string replace of /textaerea to /textarea placeholder, then before updating the database on submit i simply do the reverse, so either /textarea or /textarea placeholder will be correct and will show everything in the editor instead of closing the editor at the first occurrence of /textarea in the well, "text"

Also showing html entities really takes away from the editing of html, that is the reason i went with the replacement method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜