Skip to content
Advertisement

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 follows

JavaScript

I’m getting the error:

Undeterminnated string literal

If I remove the n from the string it works 100% but without line breaks.

Advertisement

Answer

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

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement