Hi,

I'm trying to put line breaks or have multi-lines in my alert box. When I put a \n between the lines I want to break it comes up with a javascript error "Unterminated strint constant". I know I must be missing some characters in the code. below is the example. The alert box works, but as soon as I put a \n in there, it comes up with that error.

<?php
if($count < 180)
{
echo "<script language= Javascript>
alert('test days $count');
</script>";
}

?>

Can someone tell me what I have written wrong?

    I don't believe javacript alerts can be multi line. Check in a js forum.

      I was able to make it multi-line if I put that javascript code in a variable, but I wasn't able to get the php variable $count to show up.

        try using \n\r. Or, it might be \r\n. I can never remember which comes first 🙂 Try them both.

          I just tried it and it still came up with the same error.

            ah, I see the problem. What happens is that you get your source looking like this:

            <script language= Javascript>
            alert('test days
            $count');
            </script>

            That's not good. Instead of using \n, you'll need to escape the \ like so: \n

            If you do that, then \n should be in your alert, and it will be properly converted to a newline.

              Write a Reply...