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";
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";