textarea NewLine Value

Discussion in 'HTML' started by Gene Wirchenko, Dec 29, 2011.

  1. Dear HTMLers:

    Suppose I have a textarea control on a page. The user enters a
    multi-line comment in it. I need to be able to do some clean up on
    the entered value on the frontend, and I want to know what the newline
    character(s) is. What can I count on for the value of the newline
    character(s)?

    I am using IE 9 under Windows 7, and a bit to my surprise, the
    newline is LF. I do not want to write browser-specific code though.

    I found "It is recommended that user agents canonicalize line
    endings to CR, LF (ASCII decimal 13, 10) when submitting the field's
    contents. The character set for submitted data should be ISO Latin-1,
    unless the server has previously indicated that it can support
    alternative character sets." at
    http://www.w3.org/TR/REC-html32#textarea, but this does not say
    anything about the value before submission.

    Sincerely,

    Gene Wirchenko
    Gene Wirchenko, Dec 29, 2011
    #1
    1. Advertising

  2. On Wed, 28 Dec 2011 19:05:54 -0800, Gene Wirchenko wrote:

    > Dear HTMLers:


    > Suppose I have a textarea control on a page. The user enters a
    > multi-line comment in it. I need to be able to do some clean up on the
    > entered value on the frontend, and I want to know what the newline
    > character(s) is. What can I count on for the value of the newline
    > character(s)?


    It's not really an html question, more a javascript one. ;)

    If you're asking how to clean it up in javascript, one approach that
    might work is:

    document.getElementById("id").value = document.getElementById
    ("id").value.replace(/[\r\n]+/g,"\r\n");

    This will replace any sequence of 1 or more of any combination of
    carriage returns and line feeds with a single carriage return / linefeed
    pair in the form element identified by the given id.

    Rgds

    Denis McMahon
    Denis McMahon, Dec 29, 2011
    #2
    1. Advertising

  3. Gene Wirchenko <> wrote

    > Dear HTMLers:
    >
    > Suppose I have a textarea control on a page. The user enters a
    > multi-line comment in it. I need to be able to do some clean up on
    > the entered value on the frontend, and I want to know what the newline
    > character(s) is. What can I count on for the value of the newline
    > character(s)?
    >
    > I am using IE 9 under Windows 7, and a bit to my surprise, the
    > newline is LF. I do not want to write browser-specific code though.
    >
    > I found "It is recommended that user agents canonicalize line
    > endings to CR, LF (ASCII decimal 13, 10) when submitting the field's
    > contents. The character set for submitted data should be ISO Latin-1,
    > unless the server has previously indicated that it can support
    > alternative character sets." at
    > http://www.w3.org/TR/REC-html32#textarea, but this does not say
    > anything about the value before submission.
    >


    Your best bet is to do it server side. What you propose won't work if
    the visitor has JavaScript disabled.

    --
    Adrienne Boswell
    Arbpen Web Site Design Services - http://www.cavalcade-of-coding.info/
    The Good Plate - Fresh Gourmet Recipes - http://the-good-plate.com/
    Please respond to the group so others can share
    Adrienne Boswell, Dec 29, 2011
    #3
  4. Gene Wirchenko

    Neil Gould Guest

    Gene Wirchenko wrote:
    > Dear HTMLers:
    >
    > Suppose I have a textarea control on a page. The user enters a
    > multi-line comment in it. I need to be able to do some clean up on
    > the entered value on the frontend, and I want to know what the newline
    > character(s) is. What can I count on for the value of the newline
    > character(s)?
    >
    > I am using IE 9 under Windows 7, and a bit to my surprise, the
    > newline is LF. I do not want to write browser-specific code though.
    >
    > I found "It is recommended that user agents canonicalize line
    > endings to CR, LF (ASCII decimal 13, 10) when submitting the field's
    > contents. The character set for submitted data should be ISO Latin-1,
    > unless the server has previously indicated that it can support
    > alternative character sets." at
    > http://www.w3.org/TR/REC-html32#textarea, but this does not say
    > anything about the value before submission.
    >

    For textarea, line endings are typically CrLf, as indicated in the above
    excerpt. As others have indicated, attempts to catch the CrLf before
    submission will fail if the client has scripting disabled.

    Perhaps we can help out if you would explain why you need to detect line
    endings prior to submission.

    --
    best regards,

    Neil
    Neil Gould, Dec 29, 2011
    #4
  5. On Thu, 29 Dec 2011 09:19:39 -0500, "Neil Gould"
    <> wrote:

    >Gene Wirchenko wrote:
    >> Dear HTMLers:
    >>
    >> Suppose I have a textarea control on a page. The user enters a
    >> multi-line comment in it. I need to be able to do some clean up on
    >> the entered value on the frontend, and I want to know what the newline
    >> character(s) is. What can I count on for the value of the newline
    >> character(s)?
    >>
    >> I am using IE 9 under Windows 7, and a bit to my surprise, the
    >> newline is LF. I do not want to write browser-specific code though.
    >>
    >> I found "It is recommended that user agents canonicalize line
    >> endings to CR, LF (ASCII decimal 13, 10) when submitting the field's
    >> contents. The character set for submitted data should be ISO Latin-1,
    >> unless the server has previously indicated that it can support
    >> alternative character sets." at
    >> http://www.w3.org/TR/REC-html32#textarea, but this does not say
    >> anything about the value before submission.
    >>

    >For textarea, line endings are typically CrLf, as indicated in the above
    >excerpt. As others have indicated, attempts to catch the CrLf before
    >submission will fail if the client has scripting disabled.


    That is not an issue. Scripting will be enabled. This is for an
    internal app.

    >Perhaps we can help out if you would explain why you need to detect line
    >endings prior to submission.


    I covered that: "I need to be able to do some clean up on the
    entered value on the frontend". I value a good UI. Shoving a mess to
    the server is not the way to do it.

    Sincerely,

    Gene Wirchenko
    Gene Wirchenko, Dec 29, 2011
    #5
  6. Gene Wirchenko

    Neil Gould Guest

    Hi Gene,

    Gene Wirchenko wrote:
    > On Thu, 29 Dec 2011 09:19:39 -0500, "Neil Gould"
    > <> wrote:
    >
    >> Perhaps we can help out if you would explain why you need to detect
    >> line endings prior to submission.

    >
    > I covered that: "I need to be able to do some clean up on the
    > entered value on the frontend". I value a good UI. Shoving a mess to
    > the server is not the way to do it.
    >

    Trying to clean it up as it's being typed also uses the server (to run your
    JavaScript), so it still has to deal with the same "mess", and since running
    a parsing loop is a far less efficient process, I'd still recommend parsing
    the form content on submission.

    --
    best regards,

    Neil
    Neil Gould, Dec 29, 2011
    #6
  7. Gene Wirchenko

    Tim Streater Guest

    In article <jdirlv$aj0$>,
    "Neil Gould" <> wrote:

    > Hi Gene,
    >
    > Gene Wirchenko wrote:
    > > On Thu, 29 Dec 2011 09:19:39 -0500, "Neil Gould"
    > > <> wrote:
    > >
    > >> Perhaps we can help out if you would explain why you need to detect
    > >> line endings prior to submission.

    > >
    > > I covered that: "I need to be able to do some clean up on the
    > > entered value on the frontend". I value a good UI. Shoving a mess to
    > > the server is not the way to do it.
    > >

    > Trying to clean it up as it's being typed also uses the server (to run your
    > JavaScript),


    This is incorrect. He can run JS client-side to do cleanup.

    > so it still has to deal with the same "mess", and since running
    > a parsing loop is a far less efficient process, I'd still recommend parsing
    > the form content on submission.


    --
    Tim

    "That excessive bail ought not to be required, nor excessive fines imposed,
    nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
    Tim Streater, Dec 29, 2011
    #7
  8. On Thu, 29 Dec 2011 23:19:41 +0000, Tim Streater
    <> wrote:

    >In article <jdirlv$aj0$>,
    > "Neil Gould" <> wrote:
    >
    >> Hi Gene,
    >>
    >> Gene Wirchenko wrote:
    >> > On Thu, 29 Dec 2011 09:19:39 -0500, "Neil Gould"
    >> > <> wrote:
    >> >
    >> >> Perhaps we can help out if you would explain why you need to detect
    >> >> line endings prior to submission.
    >> >
    >> > I covered that: "I need to be able to do some clean up on the
    >> > entered value on the frontend". I value a good UI. Shoving a mess to
    >> > the server is not the way to do it.
    >> >

    >> Trying to clean it up as it's being typed also uses the server (to run your
    >> JavaScript),


    No, it uses the workstation.

    >This is incorrect. He can run JS client-side to do cleanup.


    Quite, and this processing is comparatively cheap. The computer
    is likely just sitting there running the page and not much else.

    >> so it still has to deal with the same "mess", and since running
    >> a parsing loop is a far less efficient process, I'd still recommend parsing
    >> the form content on submission.


    Oh, I plan to. I expect the validation at the server end will
    generally go much faster since, usually, nothing will have to be done
    to clean the data. I suppose that an untrusting sort might log bad
    data getting to the server and consider checking whether it is a
    front-end bug or a hacking attempt, but I will leave that game for
    someone else to play.

    Sincerely,

    Gene Wirchenko
    Gene Wirchenko, Dec 29, 2011
    #8
  9. Gene Wirchenko

    Neil Gould Guest

    Tim Streater wrote:
    > In article <jdirlv$aj0$>,
    > "Neil Gould" <> wrote:
    >
    >> Hi Gene,
    >>
    >> Gene Wirchenko wrote:
    >>> On Thu, 29 Dec 2011 09:19:39 -0500, "Neil Gould"
    >>> <> wrote:
    >>>
    >>>> Perhaps we can help out if you would explain why you need to detect
    >>>> line endings prior to submission.
    >>>
    >>> I covered that: "I need to be able to do some clean up on the
    >>> entered value on the frontend". I value a good UI. Shoving a mess
    >>> to the server is not the way to do it.
    >>>

    >> Trying to clean it up as it's being typed also uses the server (to
    >> run your JavaScript),

    >
    > This is incorrect. He can run JS client-side to do cleanup.
    >

    Yikes... what a brain fart I had! Sorry if anyone was confused by my
    statement. =8-0

    --
    best regards,

    Neil
    Neil Gould, Dec 30, 2011
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chris

    default value in a textarea

    chris, Dec 22, 2003, in forum: HTML
    Replies:
    2
    Views:
    15,162
  2. Augustus
    Replies:
    1
    Views:
    338
    Ken Schaefer
    Sep 10, 2003
  3. Textarea Inside of a textarea

    , Feb 4, 2006, in forum: ASP General
    Replies:
    6
    Views:
    315
    Anthony Jones
    Feb 5, 2006
  4. chin
    Replies:
    5
    Views:
    105
  5. Replies:
    1
    Views:
    297
    Bart Van der Donck
    Jul 4, 2007
Loading...

Share This Page