471,854 Members | 1,672 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,854 software developers and data experts.

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 1780
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
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.