This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes How to store the newlines entered by enter key in textarea? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to store the newlines entered by enter key in textarea?" Watch "How to store the newlines entered by enter key in textarea?" New topic
Author

How to store the newlines entered by enter key in textarea?

M K Rayapudi
Ranch Hand

Joined: Feb 19, 2007
Posts: 157
Hi,
I need to store the text entered in a TEXTAREA control in the database, and retrieve when ever required.
Here the problem is It is not storing the new line characters (enter key), it is storing all the lines as ONE sentence.
I tried using different values for wrap attribute.(soft, hard, physical,virtual, etc), but no use.

Please help in this regard.
Thank you.


R6i
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
How are you reading, storing, and writing the value out?

Eric
M K Rayapudi
Ranch Hand

Joined: Feb 19, 2007
Posts: 157
Eric Pascarello wrote:How are you reading, storing, and writing the value out?

Eric

I am using the javascript as follows:
M K Rayapudi
Ranch Hand

Joined: Feb 19, 2007
Posts: 157
still the problem not resolved
Please help .
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42035
    
  64
For HML, a newline character is just whitespace, and will be displayed as a space character. If you want an actual line break to appear on the HTML page,. you'll need to convert all newline characters to "<br/>" before displaying them.


Ping & DNS - my free Android networking tools app
M K Rayapudi
Ranch Hand

Joined: Feb 19, 2007
Posts: 157
thank you Dittmer.
I need to store the content from the TEXTAREA in the table
and retrieve the same from TABLE and populate into that TEXTAREA.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42035
    
  64
It is not storing the new line characters

At which point along the code are the newline characters dropped? Are they still present when the servlet receives the form? Are they present in the DB? Are they present when the data is retrieved from the DB? Are they present when the JSP with the TEXTAREA is created?
M K Rayapudi
Ranch Hand

Joined: Feb 19, 2007
Posts: 157
Ulf Dittmer wrote:
It is not storing the new line characters

At which point along the code are the newline characters dropped?

While storing into the table.

I am retrieving the form data in a servlet using request.getParamter(); if I print the content of the TEXTAREA character by character as int by casting , it is showing new line as 13 & 10 (two characters). After this I am storing this value in a TABLE, in the table it is storing as one string instead multiple lines (means no special characters are stored at the new line character positions)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42035
    
  64
Then you should dig into the DB connectivity to see why it's dropping those characters. SQL and JDBC don't arbitrarily alter data they're handling, so some other piece of code may be involved.
 
GeeCON Prague 2014
 
subject: How to store the newlines entered by enter key in textarea?