permaculture playing cards
The moose likes HTML, CSS and JavaScript and the fly likes Formatting text coming from a text area Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Formatting text coming from a text area" Watch "Formatting text coming from a text area" New topic

Formatting text coming from a text area

archana vishwanath
Ranch Hand

Joined: Mar 09, 2004
Posts: 39
What I did?
I'm fetching huge data from a text area and inserting into mysql database.
I'm retriving that data and now i am displaying in a <table><tr><Td><p>
Problem im facing
Problem 1 :
Suppose if the user types one very lengthy line without any space(say)
this is a test lengthy line------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------lengthy line ends.
my <td> width gets so large to accomadate the lengthy line.I expect my <td> to be of a fixed width and I dont want the table width to get extend in this manner.
Problem 2:
I expect the text to be displayed in the same way i'm typing in the
text area.(e.g)
first line,
second line,
third line.
This too is not happening.In my case what i have typed in this example in three lines is becoming one line.
Could Somebody please throw some light on this???.
I would like to know weather im doing any mistake in
1.Data base 2.Text Area 3.In <td> 3.Or if I have to do anything in my server side.
Also please specify any reference materials for this area
Thanks in advance.
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
On the server side you can check the lenght of a string and force a break in it...

On the client side you can try playing with css...
Change the css to work with a td and not a pre field...
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
In order to display lines in your td as they are in textarea, you need to replace "\n" (or "\a\n" - I don't remember) with "<br>". Another option is to display a text inside <pre> </pre> tag.
For wraping long rows you can do one of the following:
1. If you need to handle IE only, use WRAP property on your textarea
2. Use key event handlers and insert/remove "\a\n" dynamically
3. Use JavaScript to wrap it before submition.
4. Use serverside to wrap it either before saving to DB, or before displaying.
5. Use overflow attribute inside your td, so the td will have fixed width, but user will be able to scroll it in oreder to see longer lines.
[ April 13, 2004: Message edited by: Yuriy Fuksenko ]
archana vishwanath
Ranch Hand

Joined: Mar 09, 2004
Posts: 39
Thanks guys,
Using <pre> tag is fine
1.Im able to get the text as it is in text area
2.But wrapping of lines if the line length gets more is not happening
and im using I.E 5.0
pre { white-space: -moz-pre-wrap; /* Mozilla, supported since 1999 */ white-space: -pre-wrap; /* Opera 4 - 6 */ white-space: -o-pre-wrap; /* Opera 7 */ white-space: pre-wrap; /* CSS3 - Text module (Candidate Recommendation) */ word-wrap: break-word; /* IE 5.5+ */ } div.divWidth { width:60px; }
Eric please suggest me something in the client side for word wrapping which
will work in all recent I.E versions and Netscape.
I agree. Here's the link:
subject: Formatting text coming from a text area
It's not a secret anymore!