By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

Intuitive text box

P: n/a
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 <pand
<brfor me? Thanks - MG

Sep 18 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Mon, 18 Sep 2006 08:31:47 -0700, Window Frog wrote:
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 <pand <brfor
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.
Sep 18 '06 #2

P: n/a

Ivan Marsh wrote:
On Mon, 18 Sep 2006 08:31:47 -0700, Window Frog wrote:
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 <pand <brfor
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.
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.

Sep 18 '06 #3

P: n/a

Window Frog wrote:
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 <pand
<brfor 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);
}

Sep 19 '06 #4

P: n/a
JRS: In article <11**********************@k70g2000cwa.googlegroups .com>,
dated Mon, 18 Sep 2006 20:26:51 remote, seen in
news:comp.lang.javascript, Jake Barnes <lk******@geocities.composted :
// 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.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Sep 20 '06 #5

P: n/a

Dr John Stockton wrote:
JRS: In article <11**********************@k70g2000cwa.googlegroups .com>,
dated Mon, 18 Sep 2006 20:26:51 remote, seen in
news:comp.lang.javascript, Jake Barnes <lk******@geocities.composted :
// 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.

My bad. So sorry.

Sep 25 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.