Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   how do I replace with JS newlines in textareas with <br> ???? (http://www.velocityreviews.com/forums/t932317-how-do-i-replace-with-js-newlines-in-textareas-with-br.html)

Tamer Higazi 08-04-2007 11:22 AM

how do I replace with JS newlines in textareas with <br> ????
 
Hi!
I have a form with a textarea. Now, I don't get it handled to read out
the text, and to replace the (\n) anchor with <br> fields.

As well I want to do the same back, if I call the database entries, to
replace all <br> entries with (\n) entries.

here's the sample code:

var MyString = document.feedbackneu.nachricht.value
MyString.replace(/n/,"<br>");
document.getElementById('ausgabeX').innerHTML = MeinString;


but the output is without newlines.

For any help, thank you


Tamer

Rik 08-04-2007 11:32 AM

Re: how do I replace with JS newlines in textareas with <br> ????
 
On Sat, 04 Aug 2007 13:22:38 +0200, Tamer Higazi <no@mail.de> wrote:

> Hi!
> I have a form with a textarea. Now, I don't get it handled to read out
> the text, and to replace the (\n) anchor with <br> fields.
>
> As well I want to do the same back, if I call the database entries, to
> replace all <br> entries with (\n) entries.


Which is better done on the server IMO.

> here's the sample code:
>
> var MyString = document.feedbackneu.nachricht.value
> MyString.replace(/n/,"<br>");


Unteste (yes, I'm lazy):
MyString.replace(/\n/,'<br>')?
--
Rik Wasmus

Tamer Higazi 08-04-2007 11:41 AM

Re: how do I replace with JS newlines in textareas with <br> ????
 
didn't work :(

Rik schrieb:
> On Sat, 04 Aug 2007 13:22:38 +0200, Tamer Higazi <no@mail.de> wrote:
>
>> Hi!
>> I have a form with a textarea. Now, I don't get it handled to read out
>> the text, and to replace the (\n) anchor with <br> fields.
>>
>> As well I want to do the same back, if I call the database entries, to
>> replace all <br> entries with (\n) entries.

>
> Which is better done on the server IMO.
>
>> here's the sample code:
>>
>> var MyString = document.feedbackneu.nachricht.value
>> MyString.replace(/n/,"<br>");

>
> Unteste (yes, I'm lazy):
> MyString.replace(/\n/,'<br>')?
> --Rik Wasmus


jim 08-06-2007 08:29 AM

Re: how do I replace with JS newlines in textareas with <br> ????
 
You can create text-nodes and use css to format the text without using
<br> tags. If this works for your project just do something like:
stylesheet-excerpt:
p{white-space:pre;}

script-excerpt:
document.getElementsByTagName('p')[0].appendChild(
document.createTextNode( document.feedbackneu.nachricht.value )
);


To do the replacement you'll need to cover all the possible newline
interpretations--and this varies by OS/encoding/browser (maybe other
possibilities too). See http://en.wikipedia.org/wiki/Newline

You could try something like:

var MyString = document.feedbackneu.nachricht.value
MyString.replace(/\n/g,"\n<br />");
document.getElementById('ausgabeX').innerHTML = MeinString;



All times are GMT. The time now is 04:00 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.