Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > textarea NewLine Value

Reply
Thread Tools

textarea NewLine Value

 
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-29-2011
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
 
Reply With Quote
 
 
 
 
Denis McMahon
Guest
Posts: n/a
 
      12-29-2011
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
 
Reply With Quote
 
 
 
 
Adrienne Boswell
Guest
Posts: n/a
 
      12-29-2011
Gene Wirchenko <(E-Mail Removed)> 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
 
Reply With Quote
 
Neil Gould
Guest
Posts: n/a
 
      12-29-2011
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


 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-29-2011
On Thu, 29 Dec 2011 09:19:39 -0500, "Neil Gould"
<(E-Mail Removed)> 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
 
Reply With Quote
 
Neil Gould
Guest
Posts: n/a
 
      12-29-2011
Hi Gene,

Gene Wirchenko wrote:
> On Thu, 29 Dec 2011 09:19:39 -0500, "Neil Gould"
> <(E-Mail Removed)> 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



 
Reply With Quote
 
Tim Streater
Guest
Posts: n/a
 
      12-29-2011
In article <jdirlv$aj0$(E-Mail Removed)>,
"Neil Gould" <(E-Mail Removed)> wrote:

> Hi Gene,
>
> Gene Wirchenko wrote:
> > On Thu, 29 Dec 2011 09:19:39 -0500, "Neil Gould"
> > <(E-Mail Removed)> 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
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-29-2011
On Thu, 29 Dec 2011 23:19:41 +0000, Tim Streater
<(E-Mail Removed)> wrote:

>In article <jdirlv$aj0$(E-Mail Removed)>,
> "Neil Gould" <(E-Mail Removed)> wrote:
>
>> Hi Gene,
>>
>> Gene Wirchenko wrote:
>> > On Thu, 29 Dec 2011 09:19:39 -0500, "Neil Gould"
>> > <(E-Mail Removed)> 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
 
Reply With Quote
 
Neil Gould
Guest
Posts: n/a
 
      12-30-2011
Tim Streater wrote:
> In article <jdirlv$aj0$(E-Mail Removed)>,
> "Neil Gould" <(E-Mail Removed)> wrote:
>
>> Hi Gene,
>>
>> Gene Wirchenko wrote:
>>> On Thu, 29 Dec 2011 09:19:39 -0500, "Neil Gould"
>>> <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add </textarea> within <textarea> tags? frank.moens@gmail.com Javascript 1 07-04-2007 04:00 PM
Textarea Inside of a textarea wperry1@gmail.com ASP General 6 02-05-2006 08:00 AM
Retrieve the value in TextArea with the newline preserved. chin Javascript 5 10-13-2004 01:24 AM
default value in a textarea chris HTML 2 12-22-2003 08:02 PM
Removing carriage returns from <textarea></textarea> input Augustus ASP General 1 09-10-2003 04:55 AM



Advertisments