Why does setTimeOut not delay the function?

I'm really struggling with this, but it's probably very simple: I want to display an alert a short time after the field recieves focus. I'm using the following JavaScript in the "On Focus" action of the field.
app.setTimeOut(app.alert("This should appear after a delay."),5000);
But the alert appears immediately with no delay. What am I doing wrong?

Please help, I can't find my mistake and need this working today for a deadline.

Thank you.
James


James Roberts


Voted Best Answer

Do you get any error messages in the Console?

In fact, you should…

A few things (revealed with some RTFM):

• app.setTimeOut does create an object, which is better defined as a variable, therefore

var myTO = app.setTimeOut(…) ;

• The first argument of app.setTimeOut is a string, therefore

var myTO = app.setTimeOut("app.alert(\"This should appear after a delay.\")", 5000) ;

• a TimeOut object should be cleared. This can be done as part of the delayed command, therefore

var myTO = app.setTimeOut("app.alert(\"This should appear after a delay.\") ; app.clearTimeOut(myTO) ;", 5000) ;

Note that I have not tested the code; it may still be buggy.

Hope this can help.

Max Wyss.


By Max Wyss   


Please specify a reason: