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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying text with linebreaks - dynamically 2

Status
Not open for further replies.

ahmun

IS-IT--Management
Jan 7, 2002
432
US
Hi...

I currently have a form that gathers information from a user and stores it to an Access database. One of the fields is flexible, and I allow users to enter as many spaces, new lines, etc. And capture that info verbatim into my database.

My problem comes when I want to re-display this info:
I've tried a couple of things:

if I use the <pre> tag, I am successful in outputting the user's info as they had entered it. however, when I do this, I cannot control when the user just types and types and ends up with a supre long string. The <pre> tag won't force a new line and cause the text to wrap if the string goes beyond the width of the page.

if I use any other tag, then the text gets jumbled and not as clear where the user was allowed to put in his/her own linefeeds.

example:

Education field

Input:
Bachelors - Business Accounting
Masters - Astrophysics

output with <pre> tag... all fine and dandy
Bachelors - Business Accounting
Masters - Astrophysics

------
intput:
I graduated from XYZ college with a bachelors in Underwater Basket Weaving and I have a Masters from ABC Graduate college in Skydiving Basket Weaving.

Obviously, the above line is textwrapped because this forum is design to capture both line breaks, as well as continues strings of text.

I can't reproduce the output.. since Tek-tips wonderfully causes text to wrap!

---
I guess my need is:
1. How do I do this?
2. If the explanation is too difficult to do, where should I look to learn how to do this? Earnie Eng
If you are born once, you will die twice.
If you are born twice, you will die once
 
Why does it matter if you're just displaying the data?

Curious,
[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
To redisplay linebreaks you can use this old chestnut...
Code:
strText = Replace(objRecordset(&quot;textfield&quot;),vbcrlf,&quot;<BR>&quot;)
This will replace all linbreaks in the database field with valid HTML linebreaks. Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
Tony, That sounds like a good idea.
is &quot;vbcrlf&quot; an intrinsic variable in vbscript (the language I'm using in my .asp pages) or should I hardcode the character number for a carriage return line feed)

just asking now... gonna give it a try later today. Earnie Eng
If you are born once, you will die twice.
If you are born twice, you will die once
 
Tony... it worked perfectly!

Thank you!

(and for such a simple yet brilliant idea, I'll give you a star!) Earnie Eng
If you are born once, you will die twice.
If you are born twice, you will die once
 
This is to Tony or anyone that could help me.

I have the same problem of Ahmun, I I like the solution, but ...

I know nothing about javascript ou VBscript. And I need to solve it to GET FREE OF THIS STUPID SYSTEM THAT I AM FIXING.

PLEASE, help me to go out of this s*&¨$¨¨, show me how to do it with javascript.

Roberto Lyra
 
Roberto, how are you getting this lines that don't brake? Ahmun said he was getting his from an access database, where do yours come from? There must be some server side involved and that should yield a solution...
 
This is part of my problem. I have two sources ...
At the end, both go to an Oracle Database.

1 source is:
a text database where the lines HAVE linefeed every 60 characters (or near). In this text I don’t have one paragraph in one line, it is already broke in many lines. It is really a text database from IBM, something from 80's that will be closed soon (I hope so).

2 source is:
new text that I get by browser using TEXTAREA. In this case, the text has some linefeeds, but sometimes it has long lines too. The paragraph came in one line only, one long line.

My problem is to show it.

When I use TEXTAREA with readonly, which I am using now, I need to use scrolls bars, what I don't want to use.

When I don't use any HTML tag, the both kind of text have problem with linefeed.

When I use PRE, works fine for the text with a lot of linefeed, but I have problems when I have a whole paragraph in one line without linefeed. I didn't a way to break it in many lines.


I thought that If I can change linefeed in <br> just when I show, I can display it like a regular HTML text. But I don't know JavaScript enough for it.


Any help ?


Roberto Lyra

 
This is part of my problem. I have two sources ...
At the end, both go to an Oracle Database.

1 source is:
a text database where the lines HAVE linefeed every 60 characters (or near). In this text I don’t have one paragraph in one line, it is already broke in many lines. It is really a text database from IBM, something from 80's that will be closed soon (I hope so).

2 source is:
new text that I get by browser using TEXTAREA. In this case, the text has some linefeeds, but sometimes it has long lines too. The paragraph came in one line only, one long line.

My problem is to show it.

When I use TEXTAREA with readonly, which I am using now, I need to use scrolls bars, what I don't want to use.

When I don't use any HTML tag, the both kind of text have problem with linefeed.

When I use PRE, works fine for the text with a lot of linefeed, but I have problems when I have a whole paragraph in one line without linefeed. I didn't a way to break it in many lines.


I thought that If I can change linefeed in BR just when I show, I can display it like a regular HTML text. But I don't know JavaScript enough for it.


Any help ?


Roberto Lyra

 
Ok, but when people type in the textarea, a script is called which processes the text in the textarea and spits it out. The script you're calling is usually in <form action=&quot;scriptname.ext&quot;>. This process is done server-side and it is best if you perform the replacing of line-feed characters there. But first you will have to tell us which server-side scripting you're using. If it is php, the solution is simple - function nl2br() does just that. If it is asp, you just run a similar replace function as described above. I guess it could also be done in Javascript (dwarfthrower once wrote a js script that produced links on a page load, so it shouldn't be a problem) but the server-side solutions will serve you better.
 
I have a ColdFusion server, which I think is a very good option, most of the time.

In the form I just get a variable and insert it into a table.

I didn’t thought about change it BEFORE save. I was thinking about change it after recover and before show. And in Java.

What do you think ?


Roberto Lyra
From Brazil, where things are slowly changing, for better.
 
You are great.

The paragraphformat didn't work at all, or the way I expected. But I started to look better the ColdFusion reference guide (what I supposed to do from the begin), I found a way to change my linefeeds. And I found, easy and clean.

Thank you all a lot. And the end, you show me the way to solve it.



Roberto Lyra
From Brazil, where things are slowly changing, for better.
 
Sometimes these forums produce the right method to solving a problem, rather than the solution. And that is sometimes better than the answer because you get to learn and become a better programmer! That is awesome!

Glad you can find the answer, Roberto.

Earnie Eng
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top