Linefeed problem from textarea -> variable

J

Jürgen Heyn

Good afternoon,

in a form a multiline textbox is defined:
<textarea name="text" cols="25" rows="3">This is the text.
this should be line 2</textarea>
In the textbox the linefeed is displayed correctly. Now I need to hand the
"value" property to a string variable like:
myString = document.forms[0].text.value;
In myString all linefeed commands have been deleted. Is it somehow possible
to keep the linefeed information ?
Thank you for any hint.
Best regards
Juergen Heyn, Wilhelmshaven, Germany
 
M

Martin Honnen

Jürgen Heyn said:
in a form a multiline textbox is defined:
<textarea name="text" cols="25" rows="3">This is the text.
this should be line 2</textarea>
In the textbox the linefeed is displayed correctly. Now I need to hand the
"value" property to a string variable like:
myString = document.forms[0].text.value;
In myString all linefeed commands have been deleted. Is it somehow possible
to keep the linefeed information ?

How do you check for linefeeds? Maybe it is just that on your platform a
carriage is used? You should test
/\r\n|\r|n/g.test(document.forms[0].text.value)
 
T

Thomas 'PointedEars' Lahn

Martin said:
How do you check for linefeeds? Maybe it is just that on your platform a
carriage is used? You should test
/\r\n|\r|n/g.test(document.forms[0].text.value)
^^^^ ^^^^
The test can be corrected, simplified, and made standards compliant.
Either

/\r?\n|\r/g.test(document.forms[0].elements['text'].value)

or

/\r\n?|\n/g.test(document.forms[0].elements['text'].value)


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,815
Messages
2,569,705
Members
45,494
Latest member
KandyFrank

Latest Threads

Top