Forum Moderators: open

Message Too Old, No Replies

text area - read line by line

test field

         

rsennat

3:15 pm on Nov 12, 2005 (gmt 0)



hi all,

how to read the contents of a text area line by line,
when the text entered with a enter key and several lines are visible in the text field.

But when submitting, it comes as single string separated by spaces.

But i need to get the test field line by line.

thanks
rsennat

jatar_k

3:21 pm on Nov 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld rsennat,

Can't you use the wrap attribute? I think wrap='hard' but I am not sure, you will have to test it.

rsennat

3:55 pm on Nov 12, 2005 (gmt 0)



hi jatar_k,

when using CGI Dump, for the text area, i could see that it is displayed as viewed in browser.

but when i store the value of the text area in a variable and print it, its a single string.

i need the text area to be in the string line by line. (may be array of string would be fine)

how do i get this done?

thanks
rsennat

jatar_k

4:05 pm on Nov 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the other thing is you might need to test what it is sending for new lines

is it \n or \r or both and then replace those with <br> if youo are wanting the display to go to a browser

rsennat

4:22 pm on Nov 12, 2005 (gmt 0)



hi,
actually what i need is, when submitting the data in the form, the text area field has to be read line by line.

and how to check the \n or \r

please help me to sort it out.

thanks
rsennat

rocknbil

6:07 pm on Nov 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The wrap attribute is either depricated or proprietary (in either case it doesn't validate.)

I think what you're asking has to be done with Javascript or something. When someone types and the text approaches the right margin of the box, the browser wraps it around but when submitted it still remains a single line UNLESS the user enters returns. If they do, the newlines are maintained.

So if you write some Javascript that reads the text field on each keystroke and maintains track of the current line, when each line reaches n characters it adds a \n. That could work, but keeping it consistent across all browsers will be a trick. :-D

Server-side is easy, in the language of your choice you just split on the newlines, tossing away the elements that are blank.

encyclo

8:41 pm on Nov 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



wrap="hard"
(alternative values: "soft" and "off") was invented by Netscape IIRC but only adopted by Microsoft [msdn.microsoft.com]:

hard: Text is displayed with wordwrapping and submitted with soft returns and line feeds.

It will work in IE only and was not adopted as a standard in HTML 4.0, so unless your project is for an intranet you cannot really depend on this attribute.