Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript text error on Linebreak 1

Status
Not open for further replies.

jay123454

Programmer
Jun 15, 2001
46
US
Hi,

I'm relatively new to js and have run into a problem...sure it's a simple solution so hopefully someone here can help. Basically, I'm just setting a textarea based on the value of a dropdown. I've got that part working, but I'm pulling the value of the dropdown from a mysql field (longtext). Most of these fields have linebreaks in them and I believe that's what is causing the problem. See code below. If I try and set a var to that value it will error out. But if I replace "\r\n" with nothing, it will work fine other than the fact that the linebreaks do not show up in the textarea. So I'd like to know how I can set this variable so that the linebreaks are displayed in the textarea.


<SCRIPT LANGUAGE="JavaScript">
var arrItems = new Array();
arrItems[0] = "";
<?
$sql="select * from anytable;";
$rs=query($sql);
while(!($rs->eof()))
{
$js_var=$notes_rs->get("var");
$js_var2=str_replace("\r\n", "", $js_var);
?>
arrItems[<? echo $rs->get("ID");?>] = "<? echo $js_var2;?>";
<?
$rs->movenext();
}
?>


I've tried replacing
"\r\n" with "\n"
"\r\n" with "\n +"

But same problem with both of these...The error I get is "unterminated string literal".

If I view source in Firefox it looks like this.

arrItems[0] = "";
arrItems[1] = "Dear Sir,

Thank you for the call today. I appreciate you taking the time out of your schedule.

Sincerely,

Joe Salesman";
arrItems[2] = "Hi,

This is a Test.

Joe Salesman";
 
By the way...in case you are wondering I'm using this array to set the value of the textarea by calling onchange on the dropdown.

Here's the function called onchange

function disp()
{
var ID= document.form2.var_template_ID.value;
document.form2.var_textarea.value = arrItems[ID];
return;
}
 
replace \n\r with \\n instead of \n

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
headbang.gif
[rockband]
headbang.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top