?
Solved

Showing /textarea in a textarea tag

Posted on 2003-02-27
6
Medium Priority
?
241 Views
Last Modified: 2010-04-09
I've got an ASP page that will allow a user to edit or create text files.  The page takes a filename, opens the file, and sticks the entire contents in a <textarea> so the user can edit it.

It works great until the page loads a file that has </textarea> tags in it (Say, an HMTML page).  Then the textarea on the page will contain all the text up to the </textarea> tag in the file (which is SUPPOSED to be inside the textarea) and the rest of the text shown ends up being treated as actual HTML instead of being in the textarea.

Anyone know a way around this?  I hope the explanation above makes sense.

James
0
Comment
Question by:Lycaon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 1

Author Comment

by:Lycaon
ID: 8039114
Heh, I can't edit my question because of the tags :\

Anyway, just an example of my problem.

The text file contains this:

<html>
<body>
<form>
<textarea>
</textarea>
</form>
</body>
</html>

It's basically an HTML page with a textarea on it to type in.

Now, the ASP page is meant to load the above text file and display it ALL inside a textarea.  The HTML that the ASP page sends looks like this:

<html>
<body>
Here is the file you chose to edit.
<form>
<textarea>

<!-- Actual file contents begin here -->
<html>
<body>
<form>
<textarea>
</textarea>
</form>
</body>
</html>
<!-- File contents end here -->

</textarea>
</form>

</body>
</html>

The problem is, instead of displaying the whole file in the <textarea> the browser sees the </textarea> in the file contents and 'closes' the textarea.  Then, the HTML on from </form> in the file contents is treated as real HTML instead of being treated as textarea contents.
0
 
LVL 5

Accepted Solution

by:
gator4life earned 600 total points
ID: 8039676
Lycaon -

When you output the contents of the text file into the HTML document, you can parse the text stream for the less than < and greater than > characters, and replace them with &lt; and &gt; before the text gets added into the HTML document.  Then, the HTML rendering engine will ignore the characters as HTML and instead "see" the &lt; and &gt; as just plain text.  However, when the &lt; and &gt; get displayed in the textarea, they will look like < and >.

Let me know if you need more help.

gator4life
(chomp, chomp)
0
 
LVL 5

Expert Comment

by:gator4life
ID: 8039690
So, your final HTML document should end up looking like this in the code (from your example):

<html>
<body>
Here is the file you chose to edit.
<form>
<textarea>

<!-- Actual file contents begin here -->
&lt;html&gt;
&lt;body&gt;
&lt;form&gt;
&lt;textarea&gt;
&lt;/textarea&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
<!-- File contents end here -->

</textarea>
</form>

</body>
</html>

gator4life
(chomp, chomp)
0
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 
LVL 1

Author Comment

by:Lycaon
ID: 8039993
But the &gt; and &lt; will show up as < and > in the textarea?

If that works, I'd feel so dumb :p

James
0
 
LVL 1

Author Comment

by:Lycaon
ID: 8039998
Ignore last post, that was a stupid question because you said so in your post.

Extra 50 points awarded for a quick reply, and because I can be so clueless sometimes :)

Thank you, Gator4life :p
James
0
 
LVL 5

Expert Comment

by:gator4life
ID: 8040120
No problem, James.  Just happy I could help.  I find it amazing that all of us developers can remember half of the stuff we need to know sometimes, since things change so rapidly and we need to learn so many new technologies all the time.  Forgetting something like this is easy to do after all of the more complex stuff we get into! ;-)

gator4life
(chomp, chomp)
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question