Additional help needed with preserving textarea CR/LF

Discussion in 'Javascript' started by zjw2112@yahoo.com, Oct 12, 2006.

  1. Guest

    Hello. I have some javascript code that dynamically creates a textarea
    and sets the wrap value to hard, which I thought would preserve CR/LF
    in the textarea:

    var otherTextArea = document.createElement("textarea");
    otherTextArea.setAttribute("rows", "10");
    otherTextArea.setAttribute("cols", "30");
    otherTextArea.setAttribute("id", "otherTextArea");
    otherTextArea.setAttribute("wrap", "hard");

    At the appropriate time, I add the text string in the textarea to an
    XML string using the following:

    var textArea = document.getElementById("otherTextArea");
    commentsXML += "<other>" + textArea.value + "</other>";

    Using the following example, which would be in a textarea:

    aaa
    bbb
    ccc

    where 'aaa', 'bbb', and 'ccc' all have CR/LF after them, the number of
    characters of textArea.value is 15, as expected. I have to send this
    XML string to a JSP page for processing and return, therefore I use
    AJAX to accomplish this. However, on the server-side of things, when I
    get the length between
    the XML string element <other>aaabbbccc</other>, the length is 9, i.e.
    the CR/LF is not preserved. Does anyone know what I am doing wrong?
    I've tried setting the wrap to off, but this didn't help either. Thank
    you.
     
    , Oct 12, 2006
    #1
    1. Advertising

  2. VK Guest

    wrote:
    > Hello. I have some javascript code that dynamically creates a textarea
    > and sets the wrap value to hard, which I thought would preserve CR/LF
    > in the textarea:


    It wouldn't, but it may add extra line breaks in the submitted text.
    What wrap attribute does is handling the lines wrapping inside the
    textarea.
    wrap="off" theoretically prevents wrapping, so all user input goes in
    one line until she presses Enter.
    wrap="soft" theoretically default theoretically does what you normally
    see in textarea: lines are wrapping within the textarea borders by only
    user entered line breaks are part of textarea value
    wrap="hard" theoretically has the same visual effect as wrap="soft" but
    all automated wraps are part pf textarea value - together with the
    "real" user-typed line breaks.

    I'm saying "theoretically" everywhere because "wrap" is a rather funny
    attribute: it is supported somehow by all browsers starting from NN/IE
    3rd ver. yet it never was standardized and included in any W3C DTD's.
    So whatever however it does on a particular UA - be happy with it, as
    you have neither basis nor authority to complain.

    But in application in your case as I said you don't need to "preserve
    CR/LF" in textarea and in anyway wrap="hard" has no business to it:
    unless you are trying to preserve soft wraps as physical line breaks(?)
     
    VK, Oct 12, 2006
    #2
    1. Advertising

  3. Guest

    I need to preserve the physical line-breaks, because I store the
    textarea text into the database, and later, read it from the database
    and load it into another textarea, therefore I want the string to look
    as it was entered.

    Thank you.


    VK wrote:
    > wrote:
    > > Hello. I have some javascript code that dynamically creates a textarea
    > > and sets the wrap value to hard, which I thought would preserve CR/LF
    > > in the textarea:

    >
    > It wouldn't, but it may add extra line breaks in the submitted text.
    > What wrap attribute does is handling the lines wrapping inside the
    > textarea.
    > wrap="off" theoretically prevents wrapping, so all user input goes in
    > one line until she presses Enter.
    > wrap="soft" theoretically default theoretically does what you normally
    > see in textarea: lines are wrapping within the textarea borders by only
    > user entered line breaks are part of textarea value
    > wrap="hard" theoretically has the same visual effect as wrap="soft" but
    > all automated wraps are part pf textarea value - together with the
    > "real" user-typed line breaks.
    >
    > I'm saying "theoretically" everywhere because "wrap" is a rather funny
    > attribute: it is supported somehow by all browsers starting from NN/IE
    > 3rd ver. yet it never was standardized and included in any W3C DTD's.
    > So whatever however it does on a particular UA - be happy with it, as
    > you have neither basis nor authority to complain.
    >
    > But in application in your case as I said you don't need to "preserve
    > CR/LF" in textarea and in anyway wrap="hard" has no business to it:
    > unless you are trying to preserve soft wraps as physical line breaks(?)
     
    , Oct 13, 2006
    #3
  4. Danny Guest

    Not too sure how you're checking the string, but the cr/lf in a text/plain
    input box will be \n, same in a textarea, and there's a standard way, which
    works on all more or less, YOUROBJ.style.whiteSpace='pre'; pre as in
    preSERVING as is, as in a <pre> element, the CSS being {white-space: pre}.

    Danny
     
    Danny, Oct 14, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TTroy
    Replies:
    16
    Views:
    804
    Peter Nilsson
    Jan 31, 2005
  2. Replies:
    4
    Views:
    545
  3. Augustus
    Replies:
    1
    Views:
    371
    Ken Schaefer
    Sep 10, 2003
  4. Textarea Inside of a textarea

    , Feb 4, 2006, in forum: ASP General
    Replies:
    6
    Views:
    345
    Anthony Jones
    Feb 5, 2006
  5. Mauricio Fernandez
    Replies:
    6
    Views:
    151
    Mauricio Fernandez
    Jan 31, 2007
Loading...

Share This Page