Skip to content Skip to sidebar Skip to footer

Can't Add New Lines In Javascript Alert Box?

I'm generating a string in PHP and then eventually passing this string into a JavaScript alert box, my problem is I actually can't add line breaks in my alert box. My code looks as

Solution 1:

This happens because PHP interprets the \n before JavaScript has the chance to, resulting in a real line break inside the Javascript code. Try

\\n

Solution 2:

You need to change $str to

$str="This is a string\\n";

so that the \n gets passed to the JavaScript.

Post a Comment for "Can't Add New Lines In Javascript Alert Box?"