473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Additional help needed with preserving textarea CR/LF

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
3 8151
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sambucus | last post by:
Hi group! I am using C++ and java with JNI to get some text in a RICHEDIT to my java program. I do so by accessing a C++ method every second. It all works fine except that it leaks memory every...
5
by: Mark Szlazak | last post by:
Apparently there is a textarea onscroll event bubbling bug in Firefox and Mozilla: https://bugzilla.mozilla.org/show_bug.cgi?id=229089 I'm trying to check for this bug with the following...
3
by: Robizzle | last post by:
I write a simple php script where I can post news to my website. There is an html page (makenews.html) that has forms for username (in this example it is 'admin'), password (in this example it is...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
2
by: Chris Schinzel | last post by:
Hi, I'm reading text from a html textarea field (standard wrap functionality, no value specified). If I display it via nl2br() (after html form submission), everything's ok. But if I send it via...
1
by: anbuselvan2558 | last post by:
Hi Everbody, I want to highlight some values inside the textarea through javascript. . can anyone just guide me in this approach. Thank's in Advance Regards
16
by: rite2vinoth | last post by:
HI I want to display the contents of a big XML inside a text area so that the user would be able to edit it. But the XML consists of characters such as &amp; &quot; which are interpreted by as & and "...
3
by: missred | last post by:
Hi All, I'm hoping someone can help me with this problem. the form works ok in firefox and IE6, but when send is pressed, a blank email form or a blank IE7 page comes up, instead of the message...
3
by: sophia.agnes | last post by:
Dear all, I was going through the book "C a software engineering approach by darnell & Margolis" there was a section named sign preserving vs value preserving it is as follows sign...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.