PDA

View Full Version : Arguments in setInterval (javascript)



lostinbeta
June 19th, 2003, 12:50 PM
Ok, I am really confused here. I haven't worked much with setInterval in Javascript, but I assumed it worked the same as it does in Actionscript, but apparently it doesn't.

This works in Flash...
function notify(m) {
trace(m);
}
setInterval(notify, 2000, "hello world");


This doesn't work in Javascript...

function notify(m) {
alert(m);
}
setInterval(notify, 2000, "hello world");



I checked the O'Reilly Reference in my Dreamweaver and it says in there that you pass the arguments at the end like I did there, but it just isn't working!

Anyone know what I am doing wrong?

Jubba
June 19th, 2003, 12:56 PM
not sure if this helps...

http://www.insidedhtml.com/tips/functions/ts18/page4.asp

senocular
June 19th, 2003, 01:01 PM
is there a setInterval? Ive always used setTimeout
Im so behind in my javascript. :P

lostinbeta
June 19th, 2003, 01:04 PM
Jubba: THAT LINK WAS PERFECT!!! Man I searched for 2 hours last night and didn't find ANYTHING that helped me.

Apparently Netscape does it right and IE doesn't... how ironic :P

Anywho, this works in both Netscape and IE


<SCRIPT LANGUAGE="JavaScript">
<!--
function notify(m, m2) {
alert(m+" "+m2);
}
setInterval("notify('hello world', 'are you there?')" , 2000);
-->
</SCRIPT>



Sen: Yeah setInterval exists in Javascript :)

Jubba
June 19th, 2003, 01:14 PM
4 minutes on google :)

:P

:trout:

ahmed
June 19th, 2003, 01:17 PM
yeah, it has to be in " ".. i too was kinda confused by that.. i noticed though that JS's built-in functions/methods do not need the " " outside them .. :)

lostinbeta
June 19th, 2003, 02:57 PM
Originally posted by Jubba
4 minutes on google :)

:P

:trout:

Google must hate me because that's what I was using too :-\