Jump to content

Textareas inside Textareas :(


Zeradin

Recommended Posts

I am editing code in a textarea(A).  When i end a textarea inside the code it ends the textarea containing it. It cuts off my code and screws up the editor textarea.

 

My question is like... why doesn't this:

 

</textarea> end the posting textarea here? how can I fix this problem with what i'm coding? I feel like I need to force the closing tag to close the specific textarea that most recently opened. Thanks.

Link to comment
Share on other sites

The code is really simple. I'm working with a CMS that allows you to build websites. So I'm putting code in a textarea. Basically it looks like this:

 

<!-- this is the text area i'm editing in -->
<textarea id="cms">
<b>some stuff</b>
<textarea id="mycode">stuff in the textarea</textarea>
<input type="submit" />
</textarea>

the first </textarea> closes the containing text area (CMS) and cuts off the rest of my code, rather than closing the "mycode" textarea and so the submit ends up displaying in the CMS, rather than in the code i'm inputting

Link to comment
Share on other sites

Textareas can not contain other textareas (or any HTML elements). If you want to have HTML code in your textarea, change all < > to < and >

 

<!-- this is the text area i'm editing in -->
<textarea id="cms">
<b>some stuff</b>
<textarea id="mycode">stuff in the textarea&lt/textarea>
<input type="submit" />
</textarea>

Link to comment
Share on other sites

No, they can contain the other elements, it's just a cms for writing html pages. There are things like codepress etc that are specifically written for writing code in text areas.  If I write > etc it'll just print those characters out on the html page that i'm trying to edit, rather than display the code. I just talk to someone else about it and apparently the way i'm going to try to do it is on submit look for </textarea> and change it to </textarea> and then on the way out change it back. There's gotta be a better solution though.

Link to comment
Share on other sites

No they can't contain other HTML elements. They can however contain HTML code that represents them. And no, when you convert  the < > to entities, they will display not display as entities, but as < >.

 

There's gotta be a better solution though.

 

Yeah... it's called htmlspecialchars.

Link to comment
Share on other sites

I'm working with JSP here so that isn't going to help me.

 

And that's what I'm saying about how they will display I'll have a set of nice text input boxes and then it'll print out <textarea></textarea> instead of displaying an actual textarea to receive input. I tried it.

 

I don't understand how you can keep saying "they can't contain html elements" when the whole company I'm working with has based their entire cms around putting html elements in textareas.

 

I did find a solution that's a complete work around and then another more practical solution that I can't implement. (it's not my cms)

 

The solution I used: jquery

<script type="text/javascript">
var te = '/textarea';
$("div#textarea").html('<textarea id="message" name="message"><' + te + '>');
</script>
<div id="textarea">
</div>

 

2. the solution that's better that i couldn't use: div or section with contentEditable

Link to comment
Share on other sites

Ok.

This:

<html>
<!-- this is the text area i'm editing in -->
<textarea id="cms">
<b>some stuff</b>
<textarea id="mycode">stuff in the textarea&lt/textarea>
<input type="submit" />
</textarea>
</html>

 

renders like this:

clipboard01q.png

 

Is this what you expect, or do you wish to have an actual textarea nested within a textarea?

 

 

Link to comment
Share on other sites

No. I think that we're talking about different things. It'd be like if where I'm typing this message now I could put like <b> hi</b> and it would work and then even <textarea></textarea> and the box would show up in my post.

 

the cms is for building websites, so when i enter this information, it outputs to the webpage. the containing <textarea> is only in the cms. it stores what i put in it in a database and then when the webpage is loaded it gets the data from the database and populates the page with html.

Link to comment
Share on other sites

1. When saving HTML from text area to database store < > as < >

2. When displaying HTML for rendering (on final page), display < > as < >

3. When displaying HTML to textarea (for editing), display <  > as <, >. They will display as < > and also will be submitted as < >, but you will have to change them back to < > when storing data.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.