I have a script that creates a select box, propogates it with data from mysql. When you select one of the options in the select box, It will propogate a textarea box with comments left by the person that is selected in the select box. I can get it to work okay if I put small test data into the array below, but if I use the data from the database, javascript reports errors and won't do very much. What I believe the errors to be is that there are linebreaks in the text and javascript interprets them as unterminated strings. Does anyone know how I can use php to replace linebreaks(I don't know what kind, they are copied and pasted from a mainfraime app) to \n. My code is below. The problem line I have is colored in red.
<html>
<head>
<script>
function propogate(val){
document.form1.commentsbox.value=comments1[val];
}
</script>
</head>
<form name="form1">
<select size=8 name="event1" onclick=propogate(this.value)>
</select>
<textarea name=commentsbox></textarea>
</form>
<script>
var comments1=new Array();
<?
$i=0;
while($row=mysql_fetch_array($select)){
?>
document.form1.event1.options[<? echo $i;?>] = new Option('<?echo $row[a];?> <?echo $row;?> <? echo $row[c];?>', '<? echo $i;?>');
[COLOR=red]comments1[<? echo $i;?>]="<? echo $row[d];?>";[/COLOR]
<?
$i++;
}
?>
</script>
</html>