Javascript broke with multiple line variables from PHP

I have several sites where I use a pop up table to display information if the user rolls over and image.

Example, if the user wants to view notes on a certain client, they can roll over a little "note" image to view the notes about the client pulled from a SQL database.

The code I use for a message may be:

<script type="text/javascript">
note[0] = new Array("","<?php echo $message; ?>;");
</script>

That would work if $message was all one line. But as with all notes fields, you can never determine when the person entering data hits "Enter". If the person did hit enter, your javascript would be broke and it would look like this in the source code.

<script type="text/javascript">
note[0] = new Array("","This is the start of the note field. I hit enter after this sentence twice.
 
Then I started typing again");
</script>

This broke the Javascript. To fix this you can just swap the hidden special characters with a html line break.

Working code:

<script type="text/javascript">
note[0] = new Array("","<?php echo str_replace("\r\n","<br>;", $message); ?>;");
</script>

This would return:

<script type="text/javascript">
note[0] = new Array("","This is the start of the note field. I hit enter after this sentence twice<br><br>Then I started typing again");
</script>
If you have questions about anything on this site, you can find me on Google+: