Hi Jorge,
I've got a loop through the database rows that dynamically creates the elements in the JS array.
<?php<br><br>print "<br><script language=\"Javascript\"><br>var infoArray;<br>infoArray = new Array();";<br><br>$getData = mysql_query("SELECT * FROM Information", $link);<br>while ($entry2 = mysql_fetch_array($getData))<br> {<br> $TheInfo = $entry2[Info];<br> $TheInfo = str_replace("\n", "<br>", $TheInfo);<br> $TheInfo = addslashes($TheInfo);<br> print "\n\tinfoArray[".$entry2[Day]."] = \"".$TheInfo."\";";<br> }<br><br>print "</script>";<br>?>
OK this works perfectly without line breaks in the db values. The addslashes() is a built-in function to automatically escape quotation marks and back-slashes.
Here is what the one element in the array looks like when a db value has a line break in it though:
<script language="JavaScript">
var infoArray;
infoArray = new Array();
infoArray[0] = "hi this value doesn't have line breaks and works fine";
infoArray[1] = "this one has a line break and
<br>the line has been broken";
</script>
It breaks the line in the JS code for setting the array element and that is invalid and won't work.
Do you have any ideas on how to get around this?
Thanks SO much,
- Dan