Zeradin Posted March 25, 2010 Share Posted March 25, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196515-textareas-inside-textareas/ Share on other sites More sharing options...
haku Posted March 25, 2010 Share Posted March 25, 2010 What? Why would you be embedding textareas? And without any code, it's pretty hard to give you any advice. Quote Link to comment https://forums.phpfreaks.com/topic/196515-textareas-inside-textareas/#findComment-1031751 Share on other sites More sharing options...
Zeradin Posted March 25, 2010 Author Share Posted March 25, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/196515-textareas-inside-textareas/#findComment-1031760 Share on other sites More sharing options...
Mchl Posted March 25, 2010 Share Posted March 25, 2010 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</textarea> <input type="submit" /> </textarea> Quote Link to comment https://forums.phpfreaks.com/topic/196515-textareas-inside-textareas/#findComment-1031768 Share on other sites More sharing options...
Zeradin Posted March 25, 2010 Author Share Posted March 25, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196515-textareas-inside-textareas/#findComment-1031811 Share on other sites More sharing options...
Mchl Posted March 25, 2010 Share Posted March 25, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196515-textareas-inside-textareas/#findComment-1031825 Share on other sites More sharing options...
Zeradin Posted March 25, 2010 Author Share Posted March 25, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/196515-textareas-inside-textareas/#findComment-1031868 Share on other sites More sharing options...
Mchl Posted March 25, 2010 Share Posted March 25, 2010 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</textarea> <input type="submit" /> </textarea> </html> renders like this: Is this what you expect, or do you wish to have an actual textarea nested within a textarea? Quote Link to comment https://forums.phpfreaks.com/topic/196515-textareas-inside-textareas/#findComment-1031876 Share on other sites More sharing options...
Zeradin Posted March 25, 2010 Author Share Posted March 25, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196515-textareas-inside-textareas/#findComment-1031923 Share on other sites More sharing options...
Mchl Posted March 25, 2010 Share Posted March 25, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196515-textareas-inside-textareas/#findComment-1031928 Share on other sites More sharing options...
Zeradin Posted March 25, 2010 Author Share Posted March 25, 2010 When I put < in the editing textarea it showed up on the webpage as < not as an html element. Quote Link to comment https://forums.phpfreaks.com/topic/196515-textareas-inside-textareas/#findComment-1031930 Share on other sites More sharing options...
Mchl Posted March 25, 2010 Share Posted March 25, 2010 Yeah. I've just edited my post above. You need to change < > to < > yourself when storing code from textarea to database. Quote Link to comment https://forums.phpfreaks.com/topic/196515-textareas-inside-textareas/#findComment-1031931 Share on other sites More sharing options...
Zeradin Posted March 25, 2010 Author Share Posted March 25, 2010 yes. thanks for the help. i noticed when i was looking around the internet that a lot of people have this problem. There's a lot of "hacky" solutions, like my jquery one, but at least it works now. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/196515-textareas-inside-textareas/#findComment-1031938 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.