English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have a textarea and I have some AJAX code so that as you type in the text bos everytime you hit space it sends what is in the text box off to the PHP script on the server where all the bb codes are added and then you are given a visual representation of how your message will look. The problem is that when pressing enter in my textarea the script returns it without a line break. I am using nl2br in the php script but it does nothing. I was wondering if there was any Javascript function to convert carrige returns to line breaks.

Any help is much appreciated.

Thanks

2006-08-01 22:06:04 · 2 answers · asked by mrman2289 2 in Computers & Internet Programming & Design

2 answers

Is it maybe because when you are previewing the text you are loading it into an HTML element, in which a line break is displayed like a 'space' character. If you use line breaks in your text in a table cell or div for example it won't actually show up as a new line. What I usually do for this is when I display text from a text box I replace ASCII char 10 (newline) with the '
' code so that it will display on the page as a line break. Here is a list of ASCII character values

http://www.lookuptables.com/

here is a page that shows you how to replace characters in a string using javascript

http://www.i2d.com.au/members/~benmann/javascriptreplace.html

2006-08-02 02:30:06 · answer #1 · answered by jmfc 4 · 0 0

This link might help you

http://www.google.co.uk/search?hl=en&q=how+to+AJAX+with+textarea&btnG=Search&meta=

2006-08-02 05:23:06 · answer #2 · answered by Joe_Young 6 · 0 0

fedest.com, questions and answers