Intuitive text box

W

Window Frog

Hello Javascript gurus. I have a question about a Textarea. I am typing
text or copying and pasting text into a textarea. This text contains
line breaks, paragraphs, bullets, etc. In the Textarea it looks
correct, but when saved to a database and displayed later it is all
rendered in 1 big paragraph - obviously because it lacks the proper
tags. Is there a way to get it to save with tags that correspond to its
various paragraphs, breaks, etc.? Like it literally inserts the <p> and
<br> for me? Thanks - MG
 
I

Ivan Marsh

Hello Javascript gurus. I have a question about a Textarea. I am typing
text or copying and pasting text into a textarea. This text contains
line breaks, paragraphs, bullets, etc. In the Textarea it looks correct,
but when saved to a database and displayed later it is all rendered in 1
big paragraph - obviously because it lacks the proper tags. Is there a
way to get it to save with tags that correspond to its various
paragraphs, breaks, etc.? Like it literally inserts the <p> and <br> for
me? Thanks - MG

What language are you using to write and read to and from the database?
PHP has a function to convert the formatting pretty flawlessly for textbox
data that's been stored in a database: nl2br(); (new line to <br>). I'm
not sure if there's and equivalent JavaScript function or if you'd have to
do some Regex.
 
W

Window Frog

Ivan said:
What language are you using to write and read to and from the database?
PHP has a function to convert the formatting pretty flawlessly for textbox
data that's been stored in a database: nl2br(); (new line to <br>). I'm
not sure if there's and equivalent JavaScript function or if you'd have to
do some Regex.

Hey there, I'm using VBScript to store to the db and then again to
display that data. It's going into MySQL in a TEXT type field.
 
J

Jake Barnes

Window said:
Hello Javascript gurus. I have a question about a Textarea. I am typing
text or copying and pasting text into a textarea. This text contains
line breaks, paragraphs, bullets, etc. In the Textarea it looks
correct, but when saved to a database and displayed later it is all
rendered in 1 big paragraph - obviously because it lacks the proper
tags. Is there a way to get it to save with tags that correspond to its
various paragraphs, breaks, etc.? Like it literally inserts the <p> and
<br> for me? Thanks - MG



function nl2br_js(myString) {
// 02-18-06 - this function imitates the PHP command nl2br, which
finds newlines in a string
// and replaces them with newlines plus HTML BR tags. It is the
easiest way to create the
// appearance of paragraphs when people are creating web pages by
typing text into a form.
var regXString = "\\n"
var regX = new RegExp(regXString, "g");
var replaceString = "<br /> \n";
return myString.replace(regX, replaceString);
}
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Mon, 18 Sep 2006 20:26:51 remote, seen in
news:comp.lang.javascript said:
// 02-18-06 - this function imitates the PHP command nl2br, which
^^^^^^^^
When posting to an international medium, please convert such ludicrous
date formats to something that is understandable everywhere without
ambiguity.
 
J

Jake Barnes

Dr said:
JRS: In article <[email protected]>,
dated Mon, 18 Sep 2006 20:26:51 remote, seen in

^^^^^^^^
When posting to an international medium, please convert such ludicrous
date formats to something that is understandable everywhere without
ambiguity.


My bad. So sorry.
 

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
474,104
Messages
2,570,643
Members
47,247
Latest member
youngcoin

Latest Threads

Top