11

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>
John Scipione
  • 2,360
  • 4
  • 25
  • 28

10 Answers10

26

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>
Chetan S
  • 23,637
  • 2
  • 63
  • 78
  • 14
    I heard you like textareas, so I put a textarea in your textarea so you can edit your textarea while you edit your textarea? – Chris Sobolewski Oct 28 '09 at 17:37
  • You must convert to entities. The only other (ick) solution might be to use JavaScript to convert the brackets and populate the text area, and then reconvert on submit. – Jim Zajkowski Oct 28 '09 at 18:07
3

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.

Kevin
  • 79
  • 7
2

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

Jesse Weigert
  • 4,714
  • 5
  • 28
  • 37
1

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>
Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
1

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.

Radium Chris
  • 61
  • 1
  • 8
1

Heres your solution:

Replace all <'s and >'s with

&lt; and &gt;
Jesse
  • 21
  • 1
  • This is incorrect as per the comments on the question indicate that he actually wants a fully functional `textarea` inside another `textarea` – Yi Jiang Dec 21 '11 at 11:40
0

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>
CodeJoust
  • 3,760
  • 21
  • 23
  • didn't work for me in FF 3.5. Also, I forgot to mention that I don't want to modify the inside textarea. I'll edit the question to clarify. – John Scipione Oct 28 '09 at 17:07
0

Try a hidden form field.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
0

Have you considered using FckEditor?

Paul Sasik
  • 79,492
  • 20
  • 149
  • 189
  • Yes I have considered using an editor like FckEditor but I don't want a WYSIWYG editor. I just want a plain old text editor inside of an HTML textarea. I am using EditArea Javascript to style the html code though. Check it out here: http://www.cdolivet.com/index.php?page=editArea – John Scipione Oct 28 '09 at 21:16
0

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.

mike
  • 11