How to solve this strange issue with <textarea>?

Hi there

this is my jsfiddle.net
http://jsfiddle.net/dxomcrmw/2/

problem with this approach is when I type text with pressing an enter in text area all text store in db in a single line without any line break like

gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg

I want that if I am coming in next line then text should also come in new line(cursor is coming in newline) but when I save that value in my mysql db then all data is store in one row only no line break in them

How to solve this issue?

I guess you could use Javascript to detect the line wrapping in Javascript…? What you are experiencing is pretty…usual. That’s the way it should be. Unusual in the sense that this matters.

How to use JavaScript for this thing

I am submitting these values in to the server.

I believe the usual solution is to convert stored newlines into br tags before the text gets rendered.

that is

first line \r\n
second line \r\n 
third line

will display as
first line second line third line
even though the view-source will look like

first line 
second line 
third line

but if the newlines are converted to br tags

first line <br>
second line <br>
third line

it will display as

first line 
second line 
third line

make sense?

@Mittineague
some code help more

Where to do this conversion?

Yes, seeing your code would help more.

Usually this is not a job for JavaScript
And how it looks to you in the database is not something you need to worry about

eg. if you have PHP code something like

echo $db_textarea_field;

you would do

echo nl2br($db_textarea_field);

http://php.net/manual/en/function.nl2br.php

Have you considered using something like TinyMCE http://www.tinymce.com/ for working with textareas?

When you get the text from the database to display it can’t you just use nl2br( ) iin the php code?

Oops sorry I missed @Mittineague’s response.

1 Like

I am using Servlet as backend not php

If someone can explain in terms of servlet or JSP then it would be very nice

Try the
fn:replace()
function

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.