PDA

View Full Version : Keeping Line Breaks


nurseryboy
10-06-2002, 08:35 PM
Hey guys,

I just have a little question about keeping line breaks when processing text through javascript.
What my problem is, is, I have a link:
<a href="javascript:template('$template')">Use Template</a>
($template is text coming from a mysql database),
that when the user clicks on it, it inserts the text from the database into a textarea. That all works fine, but when it gets run through the javascript to be shown, it looses its line breaks. They are in the text when it comes from the database, and even show up if I view the html source. But for some reason, javascript doesn't seem to want to keep them.
What code do I need in the function template() to make it keep the breaks? (The form name is post, and the textbox name is dscp, if that may help.)
I am a total novice at javascript, so any help would be appreciated.

Thanks a lot for your time and help,

Matthew

duniyadnd
10-07-2002, 02:48 AM
break your code up, sometimes i noticed that php doesn't read javascripts too well.

so in your case:

<? echo "<a href="; ?>

"javascript:template

<?echo "('$template')">Use Template</a>"; ?>

That "might" work, I'd need the entire code to fiddle around with it, but yeah, my experience says don't mix the two together, and its not just my javascripting code that messes up, it's other people's examples that don't work either. :rolleyes:

Duniyadnd

glenngv
10-07-2002, 03:01 AM
in your server-side code, replace all occurrences of line breaks with \n

nurseryboy
10-07-2002, 03:30 AM
Ok, thanks to the both of you.
I will try both and see what happens.
Thanks a lot!

Matthew