SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DOM Object not holding all line breaks for Textarea

    I have a very large string all contained in a DOM object and not written to a textarea until all the pieces of the string are gathered in memory. As I acquire each componet of the string I place a \r\n after the piece (sometimes a double \r\n\n). While an alert(); picks this up perfectly -- the textarea is not reading the line breaks correctly. Does anyone have an explanation for this?

  2. #2
    SitePoint Zealot alfred3x's Avatar
    Join Date
    Aug 2003
    Location
    Toronto
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you show us the code for the textarea?
    - A. Alfred Ayache
    PHP/MySQL ZCE

  3. #3
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only way I got a text area to retain escaped line breaks reliably was to set a css property- textarea{white-space:pre}

    If you don't, the textarea will wrap long lines of text in addition to your formatted line breaks.
    The problem is not as bad, in my opinion, as the solution-
    you will have to scroll horizontally, now, to read those long lines.

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have used the <pre> tags and I have also just discovered the sitepoint blog describing this problem in detail. (http://www.sitepoint.com/blogs/2004/...-javascript/):

    "When you assign a string to the value attribute of an input object, IE silently converts your nice \n line endings to the platform preference."

    His solution however does not work either:

    "Bizzarely, if you assign to the value attribute of a hidden form field object no conversion takes place; the line endings are only changed if you assign to a text area."

    This solution is still not working for me. Right now I am trying to think of a way to convert my DOM object to a Session("object") variable and then place that value in the textarea. Unfortunately I have to take a trip to the server in order to accomplish this.

    There has got to be a better way. Surely javascript has some hack or workaround for this.


Bookmarks

Posting Permissions

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