Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Code in Textarea?

Status
Not open for further replies.

econnections

IS-IT--Management
Apr 28, 2006
30
GB
Hello,

I'm creating a TechNotes DB where I can store solutions to problems I have had when coding. It allows me to copy code into a Textarea which is submitted to a meno field in an MS Access DB.

The problem is then viewing the code when retrieved from the DB without it running in the page. To resolve this the code put it into a Textarea but as shown only part of the code is now visable although its all in the DB.

Any ideas, please.
...................................

This is what is submitted and stored in the DB:::::::::::

<html>
<head>

</head>

<body>
<form name="form1" method="post" action="">
<p>
<textarea name="textarea"></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>



This is what is displayed:::::::::

<html>
<head>

</head>

<body>
<form name="form1" method="post" action="">
<p>
<textarea name="textarea">
 
Sorry, its actually running the code. After the last line on my page there is a textarea and submit button. So the question is how do I stop the code from running?
 
You will want to encode the html before you put it in the database, so when it outputs it, it doesn't keep it as html it shows it on the page...

For php you would use:
Code:
$str = "<b>bold</b>"
echo htmlentities($str)

outputs: &lt;b&gt;bold&lt;/b&gt;

ASP
Code:
Dim str
str = "<b>bold</b>"
Response.write Server.HTMLEncode(str)

outputs: &lt;b&gt;bold&lt;/b&gt;

Code:
as you can see it will output it like this:
&lt;b&gt;bold&lt;/b&gt;

but on in the browser it will look like this:
<b>bold</b>

This will work for any type of html.

I don't believe you would want to use javascript for this, because it would then change all special characters to the user in the textbox before its saved, you only want to do this in the backend before putting it in the database...


Jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top