how to detect <enter> in textarea??

They have: 164 posts

Joined: Nov 2001

how to detect or in textarea??

when user press enter, it will brings the user to a new line but when i save into the database, it will save as if it's a new sentence instead of having all the newlines.

what can i do in order to save exactly wat user types in the textarea to the database, so when i retrieve it out, it will be exactly the same as wat user types???

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

What language are you using? You'll want to search for \n, and replace with .

ASP: Replace(strMyString, vbCrLf, "")
PERL: $string =~ s/\n//g;
PHP: nl2br($my_string)

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 164 posts

Joined: Nov 2001

actually i plan to use javascript

&lt;script type="text/javascript"&gt;
function detectKey() {
    if (event.keyCode==13) {alert ("<br>")
}
}
&lt;/script&gt;
'

but instead of alert, i want to insert in the textarea. how am i suppose to do tat??

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

replace \r and/or \n and/or a combination of \r and \n with . You should be able to search and replace items in a string even with JavaScript, but it's easier with Server Side scripting.

They have: 164 posts

Joined: Nov 2001

how to replace using javascript?

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

You would search and replace the bad characters in the string on the way into the database -- which brings us back to Mark's question: what language are you using to talk to your database?

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.