I am using the following code, The only alert I get is the alert(t). I have tried unsafeWindow.setTimeout, window.setTimeout, and other variations including setInterval – nothing is working.
$('#on').change(function () { t = setTimeout(function () { starttimer() },1000);timer_on = true;alert(t); });
function starttimer() {
alert('triggered');
if (timer_on) {
alert('timerstarted');
t = setTimeout(function () { startimer() },1000);
}
}
Edit: No errors, either. The script continues to execute and t has a normal value, just the function never runs.
Don’t write code like that! Learn to love jsBeautifier and JSLint.
What version of FF and Greasemonkey are you using? Some combos had problems with alerts inside timers and/or event listeners.
Anyway,
$('#time').val ()is probably not present or not what you think it is. Does$('#time')refer to an<input>?Try this code: