If you want to use this in a function, consider the following:
function alertmsg(message) {
alert(message);
// Escape single quotes in message
message = message.replace(/'/g,"\\'");
setTimeout ("alertmsg('" + message + "')", 10000);
}
That fails in several ways for
alertmsg("I'm happy because my backslash (\\) is slanted!\nYes I am");
You handle the ', but the "\" is interpreted as an escape and is lost
(because '\)' becomes ')', and the newline is also used literally,
giving a syntax error, since newlines are not allowed inside string
literals..
Otherwise, follow McKirahan's advise...
That will work, but requires a global variable.
There is one other way, that sadly only works in IE from version 5.5:
using a function as argument to setTimeout:
---
function alertmsg(message) {
alert(message);
// Escape single quotes in message
setTimeout (function(){alertmsg(message);}, 10000);
}
---
This constant recalling, which was not in the original posters code,
is better handled with setInterval anyway:
---
function startalerts(message) {
return setInterval(function(){alert(message);},10000);
}
---
The equivalent for the original poster's problem is:
var message = "whatever";
setTimeout(function(){alert(message);},10000);
/L