Click to See Complete Forum and Search --> : Saving textarea and display like HTML


Squall Leonhart
11-24-2003, 04:15 PM
Hi, guys.
I have question again.
Please take a look at code.

<HTML>
<HEAD>
</HEAD>
<BODY LEFTMARGIN=0 MARGINWIDTH="0" MARGINHEIGHT="0">
<form name="frmAdd" method="post" action="updateMSI.asp?state=add" onsubmit="return add();">
<table border="0" cellpadding="3" cellspacing="1" width="100%" class="forumline">
<tr>
<td class="row1" valign="top"><span class="gen"><b>Content</b></span></td>
<td class="row2" valign="top"><span class="gen"> <span class="genmed"><textarea type="text" rows="15" cols="35" wrap="virtual" style="width:450px" tabindex="3" name="content"></textarea></span></td>
</tr>
<tr>
<td class="catBottom" colspan="2" align="center" height="28"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</BODY>
</HTML>

As you can see, when I type following text in text area

Hi Team:

This morning we released our financial results for the third quarter of 2003 (please see attached News Release or check out the Wins Bulletin Board on each of your floors).

Last quarter we discussed going for a ˇ°three-peatˇ± and we are pleased to announce that we did it!


And click submit and it saves on the database alright.
But problem is when I get this text from databse to display on following page.


<html>
<head>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<%
dim todaysDate
Dim adoCon 'Holds the Database Connection Object
Dim rsGuestbook 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb")
Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
num=Request.QueryString("ID")

strSQL = "SELECT * FROM tblMSI WHERE ID =" & num
rsGuestbook.Open strSQL, adoCon
todaysDate=rsGuestbook("Date")
%>
<table width="90%" border="1" bordercolor="#666666" align="center" cellpadding=20>
<tr>
<td bgcolor="#CCCCCC" height="300" bordercolor="#666666">
<% Response.Write (rsGuestbook("Content")) %>
</td>
</tr>
</table>
<%
'Reset server objects
rsGuestbook.Close
Set rsGuestbook = Nothing
Set adoCon = Nothing
%>
</body>
</html>

Text appears like this!

Hi Team: This morning we released our financial results for the third quarter of 2003 (please see attached News Release or check out the Wins Bulletin Board on each of your floors).

How can I make it display like same as when I entered it?
Just like this forum.

GlennCarter
11-27-2003, 07:11 AM
What you have to do is go through the textarea text before you upload it and replace Carriage returns with "<br />

A=CStr(request("content"))
B=""

for n=1 to len(A)
if mid(A,n,1)=chr(13) or mid(A,n,1)=chr(10) then
if mid(A,n,1)=chr(13) then B=B & "<br />"
else
B=B & mid(A,n,1)
end if
next

That code should stick your re-formatted text in a str called B. Upload B to your database and bobs your uncle.

I suggest also getting rid of the textarea property "WRAP=VIRTUAL".