Linefeed problem from textarea -> variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jürgen Heyn

    #1

    Linefeed problem from textarea -> variable

    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


  • Martin Honnen

    #2
    Re: Linefeed problem from textarea -&gt; variable



    Jürgen Heyn wrote:
    [color=blue]
    > 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 ?[/color]

    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)

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: Linefeed problem from textarea -&gt; variable

      Martin Honnen wrote:
      [color=blue]
      > 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)[/color]
      ^^^^ ^^^^
      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

      Comment

      Working...