How to transfer breaks from a textarea ?

E

EnjoyNews

Hi

I have a little probelm.

I tranfer som data from input fields to a div so you can see how a profil
will look as you type in your data.
I just put this in my input field:
onkeyup="document.getElementById('javao').innerHTML=this.value;"
And this : <span id="javao"></span> somewhere else on the page.

This works fine and I also do the same thing with a textarea.
But... The breaks made in the textfield is not tranfered to the div.
I have search the net but can't seem to find anything about it. I have also
tried different solutions using nl2br and so on, but I just can't get it to
work.


So the quetion is, how do I transfer the the enter key from a textarea ?
 
G

GArlington

Hi

I have a little probelm.

I tranfer som data from input fields to a div so you can see how a profil
will look as you type in your data.
I just put this in my input field:
onkeyup="document.getElementById('javao').innerHTML=this.value;"
And this : <span id="javao"></span> somewhere else on the page.

This works fine and I also do the same thing with a textarea.
But... The breaks made in the textfield is not tranfered to the div.
I have search the net but can't seem to find anything about it. I have also
tried different solutions using nl2br and so on, but I just can't get it to
work.

So the quetion is, how do I transfer the the enter key from a textarea ?

You need to replace all <cr><lf> [text end-of-line] in textarea with
<br/> [HTML end-of-line]
 
E

EnjoyNews

"GArlington" <[email protected]> skrev i en meddelelse
Hi

I have a little probelm.

I tranfer som data from input fields to a div so you can see how a profil
will look as you type in your data.
I just put this in my input field:
onkeyup="document.getElementById('javao').innerHTML=this.value;"
And this : <span id="javao"></span> somewhere else on the page.

This works fine and I also do the same thing with a textarea.
But... The breaks made in the textfield is not tranfered to the div.
I have search the net but can't seem to find anything about it. I have
also
tried different solutions using nl2br and so on, but I just can't get it
to
work.

So the quetion is, how do I transfer the the enter key from a textarea ?

You need to replace all <cr><lf> [text end-of-line] in textarea with
<br/> [HTML end-of-line]

ok... so the line breaks is actually <cr><lf> in a textarea ?
But how do I replace this on the run in javascript ?
 
G

Guest

ok... so the line breaks is actually <cr><lf> in a textarea ?
But how do I replace this on the run in javascript ?
Something of this sort --

function clean(asd) {
asd=asd.replace(/\r/g,"") //supress 'returns' used in IE and Opera
asd=asd.replace(/\n/g,sing) //new line --> space or <br> }

(yes, can be inline as
newstring=oldstring.replace(/\r/g,"").replace(/\n/g,sing)

where sing = "<br>" or "<p>" (remember to add the </p> also)

You might want to worry about tabs (\t) and extra spaces and multiple
'enter's
 
B

Bart Van der Donck

Thomas said:
Nonsense.

No. RFC 2616 removes all doubt:

| HTTP/1.1 defines the sequence CR LF as the end-of-line marker
| for all protocol elements except the entity-body (see appendix
| 19.3 for tolerant applications).

and

| When in canonical form, media subtypes of the "text" type use
| CRLF as the text line break. HTTP relaxes this requirement and
| allows the transport of text media with plain CR or LF alone
| representing a line break when it is done consistently for an
| entire entity-body.

For me it is obvious that text-types in the body of the transfer can
use anything they want, because HTTP must keep its hands from that.
HTTP must only offer the data exactly as they are. But this stands
apart from the HTTP-protocol itself, which is imperative about
newlines: use \r\n.

The main \r\n-rule was only relaxed to be sure that everything is
transmitted without touching it. But I think you can smell from the
text how recommended it is to use the canonical form with \r\n.
I did not write what you quoted.  Is Google Groups this borken that it
removes "`--<SP><CR><LF>"? as well?

It looks like that, yes. Try again with this article :)
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top