Codefixer - ASP tutorials, resources and software
ASP.NET 3.5/2.0 Hosting – Click Here
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Saturday 10 May
MembersPro PayPal - ASP Membership software

DiscountASP.NET – ASP.NET 3.5/2.0 Hosting


ASP Partner ASP Partner ASP Partner more partners...

Textarea formatting replacing vbCrLf with <br>

When you enter text into a textarea in a HTML form and press enter for line breaks on your keyboard the line breaks are removed and not preserved when you display the entered text on a web page that receives the textarea value.

For example below we have the code for two pages "form.asp" and "form_receive.asp".

form.asp:

<html>
<body>
<form name="form1" method="post" action="form_receive.asp">
<textarea name="myTextareaBox" cols="30" rows="5"></textarea>
<br>
<input name="Submit" type="submit" value="Submit">
</form>
</body>
</html>

form_receive.asp:

<html>
<body>
<%
Dim myTextAreaVariable
myTextAreaVariable= Request.form("myTextareaBox")
Response.write myTextAreaVariable
%>
</body>
</html>

In practice the code for "form.asp" would display a textarea such as the one below. (note that the textarea below is just an example and the submit button won't work)
If I entered the following text in the textarea below and hit the submit button, the line breaks wouldn’t show up on our example page "form_receive.asp" which receives and displays the textarea value in a browser.





The page would display;

Hi,Thanks for the invite. Regards,Michael.


The simple explanation is that when you enter a carriage return into the textarea box the browser won’t pick up carriage returns. To maintain the carriage return we could simply replace the carriage return with the <br> tag using the Replace function.

To ensure proper formatting our code for "receive_form.asp" would look like this:

<html>
<body>
<%
Dim myTextAreaVariable
Request.form("myTextareaBox")
MyTextAreaVariable=Replace(Request.form("MyTextareaBox"),vbCrLf,"<br>")
Response.write myTextAreaVariable
%>
</body>
</html>





If you have any code snippets to share with full credit given then send an email to Codesnippets - You'll receive full credit and a link back to your site.

ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software