Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browsers ignore line breaks!

Status
Not open for further replies.

externalError

Programmer
Jan 26, 2002
5
0
0
AE
Hi all,
I'm having the following problem ...

I have a TEXTAREA input field inside a form, when I try to manipulate the contents of that TEXTAREA I notice that the browser removes line breaks!
For example, if I type the following text in the TEXTAREA:

THIS IS A TEXTAREA FIELD.

THANK YOU.


When I try to display the content of the TEXTAREA I get this:

THIS IS A TEXTAREA FIELD. THANK YOU.

What do you suggest, guys?

Regards.
 
Huh? This is working fine with me:

<textarea cols=&quot;35&quot; rows=&quot;15&quot;>This is a textarea

Thank you!

This is on yet another line
*** Don't eat yellow snow! ***
 
starway...I dont think you got the problem, he needs to go the other way.

I have never had that problem, you might try checking you text editor, might be there that the problem is. Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
theEclipse,
I understood the problem properly.
The problem is that carriage returns that you create by hitting [Enter] in browser forms are not displayed properly in HTML.

If you try to create a simple form with textarea and a button that will show textarea.value in another window you'll see it yourself - all text will be displayed in one line. There's no any connection to text editors, it's the problem of browser interpreting carriage returns chars. If you see that some form (like on this forum) shows all lines after submittion the way you entered them, this means that the problem is known and was solved.

In order to make it work properly you have to convert all carriage returns using charCodeAt() function, and the best example I saw is the one I suggested: I had the same problem once and solved it using that script.
 
in that situation, couldn't you just use the wrap attribute of the textarea tag?

ex:
<textarea rows=10 cols=25 wrap=(physical||virtual)>
...
...
</textarea>

frow webmonkey.com (
There are three possible wrap options:

wrap=physical wraps the text in the input field and sends it to the server just as it appears on screen. Unless you're actually adding a CGI script, it doesn't matter whether you use this or wrap=virtual.

wrap=virtual creates the appearance of wrapped text, but sends the input to the server as if it were one long line.

wrap=off is the same as not having the wrap attribute there at all.... I'm not really sure why you'd bother with it.



would that not solve that problem ? Robert Carpenter
questions? comments? thanks? email me!
linkemapx@hotmail.com
Icq: 124408594
online.dll

AIM & MSN: robacarp
 
theEclipse,
Textarea wrap attribute doesn't have any connection to the problem. And it doesn't solve it.

The only way to fix carriage returns issue is to convert it. Simply try this example yourself and you'll see what we are talking about. Just write the value of textarea into document body, it's so simple! Do it without any char convertion, with wrap that you suggested, and then with char convertion script. You'll see it all with your eyes.

It is commonly done on server side during form processing (that's why not everybody knows about this problem), but is also possible by javascript using the method I mentioned.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top