This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Preserving newlines in Textarea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Preserving newlines in Textarea" Watch "Preserving newlines in Textarea" New topic
Author

Preserving newlines in Textarea

Tom Katz
Ranch Hand

Joined: Aug 19, 2002
Posts: 169
JSP contains textarea that can display data with various types of newlines (CR, LF, CR/LF). All various types of newline display fine, the problem is when the data is edited and the form posted.

The only situation where there's an issue is when message data contains '0A' (LF) by itself. On posting the form, these are converted to 'ODOA' (CR/LF). I only see this in Internet Explorer, it does not seem to happen in Firefox.

I've tried to no avail:
* grabbing the value/innerText/innerHTML values
* cloning the textarea element and grabbing that clone's innerText
* setting style=white-space:pre;
* changing the Page/Browser encoding values

Anyone know of way to preserve original newline bytes in IE as I described?

thanks in advance,
Tom
Tom Katz
Ranch Hand

Joined: Aug 19, 2002
Posts: 169
Clarification: the conversion does not happen on post, that just happened to be when I noticed it. Actually, there's a difference in IE vs. Firefox for displaying '\n'. Firefox's textarea contains only '\n' (0a), while IE will expand it to '\r\n' (0d0a).
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60739
    
  65

I do not believe that you will be able to change IE's behavior. You'll just have to detect and deal with the differences.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tom Katz
Ranch Hand

Joined: Aug 19, 2002
Posts: 169
Thanks - that's what I was afraid of.
 
jQuery in Action, 2nd edition
 
subject: Preserving newlines in Textarea
 
Similar Threads
notepad not supporting new line character
Help on Creating a Jar file for my JavaBean
image file upload problem
Newline Vs Carriage return
Problem with linefeed