• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Formatting text coming from a text area

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
What I did?
-----------
Step:1
I'm fetching huge data from a text area and inserting into mysql database.
Step:2
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)
(e.g)
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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
https://coderanch.com/t/114515/HTML-JavaScript/prob-pre-tags
Eric
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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) http://www.w3.org/TR/css3-text/#white-space */ 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic