473,758 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.create Element("textar ea");
otherTextArea.s etAttribute("ro ws", "10");
otherTextArea.s etAttribute("co ls", "30");
otherTextArea.s etAttribute("id ", "otherTextArea" );
otherTextArea.s etAttribute("wr ap", "hard");

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

var textArea = document.getEle mentById("other TextArea");
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>aaabbbcc c</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 8185
VK

zj*****@yahoo.c om 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 "theoretica lly" 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.c om 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 "theoretica lly" 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.w hiteSpace='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
1223
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 call I make to the C++ method. Can anyone please help me with this problem? I am not sure wether the leakage is in the C++ or java code. But i guess it's on the C++ side since I'm kind of newbee there.
5
2023
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 script and it *seems* to work. In IE it reports "bubbling" and in Firefox "not bubbling" but I really have no direct way to confirm the Firefox results until the bubbling bug is fixed.
3
1703
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 'admin'), subject line and message body. Once I fill out the information and click submit, the html page sends the info to makenews.php. This script starts out with: <?php if ($_POST == "admin" && $_POST == "admin"){ //do all of the news...
16
5137
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. And K&R2 mentions "signed extension" everywhere. Reading some old clc posts, I've beginning to realize that these books are over-generalizing the topic. I am just wondering what the difference between the following pairs of terms are: 1)...
2
7834
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 mail() the receiver gets each single line break (originating from textarea) displayed by TWO line breaks. So the text needlessly gets inflated... Can anybody help me out what to do to handle this problem? Thanks in advance!
1
1050
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
4415
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 " respectively. But if this going to be the case the backend systems could not read them. I used <xmp>, but it is already deprecated and further it would not work inside text area. Could somebody help me with this. in short : &amp; should be displayed...
3
1896
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 being relayed directly to my email. This is the code, and thanks in advance!: <div id="form"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <form action="MAILTO:ruth@ruthpiazzon.com" method="post" enctype="text/plain">
3
3301
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 preserving rule:- when signed and un signed objects meet in an expression, the result is
0
10076
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9885
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9740
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8744
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7287
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6564
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5332
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3402
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2702
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.