469,333 Members | 4,550 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,333 developers. It's quick & easy.

multiline alert not working

23
I have this alert that works:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var monitor = setTimeout("alert('The monitor is working!');",0);
  3. </script>
  4. </head>
But I want to turn the alert message into a multiline alert, and when I do this:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var monitor = setTimeout("alert('The monitor is working!\n\ntest line two');",0);
  3. </script>
  4. </head>
It doesn't work, any ideas what I'm missing here?

-- PS the timeout is set to 0 for testing purposes only, otherwise it would have a value of 10000
Sep 17 '07 #1
4 1733
gits
5,390 Expert Mod 4TB
hi ...

you have to escape the backslahes for the linefeed:

Expand|Select|Wrap|Line Numbers
  1. setTimeout("alert('The monitor is working!\\n\\ntest line two');",0)
kind regards
Sep 17 '07 #2
Z1P2
23
ohh, thank you very much. It works great now!
Sep 17 '07 #3
dmjpro
2,476 2GB
hi ...

you have to escape the backslahes for the linefeed:

Expand|Select|Wrap|Line Numbers
  1. setTimeout("alert('The monitor is working!\\n\\ntest line two');",0)
kind regards
Why should I put double slashes?
Please let me know !

Kind regards,
Dmjpro.
Sep 17 '07 #4
gits
5,390 Expert Mod 4TB
the normal and better way would be:

Expand|Select|Wrap|Line Numbers
  1. setTimeout(function() { alert('test\nline2') }, 0)
as you can see here we may use the single slash. but when using:

Expand|Select|Wrap|Line Numbers
  1. setTimeout("alert('test\nline2')", 0)
javascript tries to evaluate the string and we get an unterminated string literal:

Expand|Select|Wrap|Line Numbers
  1. alert('test\n
i think it evals it as a linefeed in our js-code ... so we have to escape the slash again:

Expand|Select|Wrap|Line Numbers
  1. setTimeout("alert('test\\nline2')", 0)
and now it is working.

kind regards
Sep 17 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Rasmus Fogh | last post: by
reply views Thread by Krzysztof Fink-Finowicki via .NET 247 | last post: by
4 posts views Thread by Michael C | last post: by
40 posts views Thread by Edward Elliott | last post: by
11 posts views Thread by Brian | last post: by
6 posts views Thread by Zdenek Maxa | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.