Thursday, October 04, 2007

Multiline arguments to a javascript function

While creating Jmail I needed to input a multiline argument into a javascript function. It seems it can't be done!

I had to replace chr(13) + chr(10) with '$nl$' (any code would do) so the argument did not include line breaks, and then replace '$nl$' with chr(13) + chr(10) in the javascript function.

For the first bit I used

str_replace(chr(13).chr(10), '$nl$', $row['body']);

in php. If you want to see the code for the last bit, just go to the link above and look at the source.

No comments: