By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,631 Members | 826 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,631 IT Pros & Developers. It's quick & easy.

Additional help needed with preserving textarea CR/LF

P: n/a
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 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
VK

zj*****@yahoo.com 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 12 '06 #2

P: n/a
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:
zj*****@yahoo.com 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 '06 #3

P: n/a

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 <preelement, the CSS being {white-space: pre}.

Danny
Oct 14 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.