Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Showing /textarea in a textarea tag

Posted on 2003-02-27
6
Medium Priority
?
269 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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

571 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