Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    New Coder
    Join Date
    Nov 2003
    Location
    Canada
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Saving textarea and display like HTML

    Hi, guys.
    I have question again.
    Please take a look at code.


    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

    quote:
    --------------------------------------------------------------------------------

    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 Othree-peatP 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.


    code:--------------------------------------------------------------------------------
    <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!

    quote:
    --------------------------------------------------------------------------------

    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.

  • #2
    New Coder
    Join Date
    Nov 2003
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Get the functions used in a forum where they insert those special tags and the when submitting the convert these to html tags. Then when you write the tex tin the db to the browser it will interpret the html tags and your formatting will be intact.

    Download a free ASP forum and find their formatiing functions.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Add the <pre> tag to preserve linefeeds

    <td bgcolor="#CCCCCC" height="300" bordercolor="#666666">
    <pre>
    <% Response.Write (rsGuestbook("Content")) %>
    </pre>
    </td>

    The default font for <pre> tags is Courier, just change it by defining a CSS style for it.

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Wouldn't Server.HTMLEncode work too?
    OracleGuy

  • #5
    New Coder
    Join Date
    Nov 2003
    Location
    Canada
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wouldn't Server.HTMLEncode work too?
    It doesn't work.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you want to preserve line breaks that were entered in a textarea, but want them to display in HTML, you'll need to use something like this:
    Code:
    Function VbCrLfToBreak(ByVal str)
    	If IsNull(str) Then Exit Function
    	VbCrLfToBreak = Replace(str,vbCrLf,"<br />")
    End Function
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    whammy's code should work, and mine too.

  • #8
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    would you use it when recording or when displaying?

  • #9
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Displaying.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #10
    New Coder
    Join Date
    Jul 2002
    Location
    Los Angeles
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's a function in Jscript using regExp.

    Code:
    // This prints out text with html breaks
    function textToHtml(text) {
    	// replace \n with <br>
    	text = text.replace(/\n/g, "<br>");
    	return text;
    }

  • #11
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cool guys... useful thread for me as well

  • #12
    New Coder
    Join Date
    Nov 2003
    Location
    Canada
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So I entered code like this
    Code:
    <html>
    <head>
    <script language="JavaScript" type="text/javascript">
    function textToHtml(text) {
    	// replace \n with <br>
    	text = text.replace(/\n/g, "<br>");
    	return text;
    }
    </script>
    
    </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>
    It seems words are sticking together still.....
    Do you know which part need to be fixed to utilize that script?

  • #13
    New Coder
    Join Date
    Jul 2002
    Location
    Los Angeles
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try the stuff in red:
    -----
    Code:
    <html>
    <head>
    <script language="JavaScript" type="text/javascript">
    function textToHtml(text) {
    	// replace \n with <br>
    	text = text.replace(/\n/g, "<br>");
    	return text;
    }
    </script>
    
    </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">
    
    <script language="JavaScript" type="text/javascript">
    	document.write(textToHtml(<%=(rsGuestbook("Content"))%>);
    </script>
    
    </td>
    </tr>
    </table>
    <%
    'Reset server objects
    rsGuestbook.Close
    Set rsGuestbook = Nothing
    Set adoCon = Nothing
    %>
    </body>
    </html>

  • #14
    New Coder
    Join Date
    Jul 2002
    Location
    Los Angeles
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is the VBScript version, use the stuff in red:
    -----
    Code:
    <html>
    <head>
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <%
    Function VbCrLfToBreak(ByVal str)
    	If IsNull(str) Then Exit Function
    	VbCrLfToBreak = Replace(str,vbCrLf,"<br />")
    End Function
    
    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 VbCrLfToBreak((rsGuestbook("Content"))) %> 
    </td>
    </tr>
    </table>
    <%
    'Reset server objects
    rsGuestbook.Close
    Set rsGuestbook = Nothing
    Set adoCon = Nothing
    %>
    </body>
    </html>

  • #15
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey Oakendin... You are pretty handy. You should hang around here more often


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •