setInterval(F(x));

G

George Hester

Hoe can I use setInterval where its argument is a function which also has an argument? For example I have a function change(Msg) where Msg is dynamically generated and returns nothing at this point (other than true I guess). I would like to have setInterval(change(Msg)); but that doesn't work. Any suggestions? Thanks.
 
I

Ivan Marsh

Hoe can I use setInterval where its argument is a function which also
has an argument? For example I have a function change(Msg) where Msg is
dynamically generated and returns nothing at this point (other than true
I guess). I would like to have setInterval(change(Msg)); but that
doesn't work. Any suggestions? Thanks.

Who you callin' a hoe?!?!

JavaScript encapsulated in PHP:

print("setInterval(\"GetTime(document.getElementById('\" + TimeAnchor.id
+\"'))\", 1000);");

Let me see if I can strip out the PHP for you:

setInterval("GetTime(document.getElementById(' + TimeAnchor.id +')),
1000);");

Calls a function with setInterval and passes an argument to that function.
 
G

George Hester

No one except my clumsy digits.

I tried it. I didn't work. Let me be nore specific:

Msg = "1<div>2<div>3<div>4<div>5<div>6"

change() just changes the visibility status of a div in the page. When Msg="" then the div is hidden. When Msg<>"" then the div is visible.

So I did this:

setInterval("change('+Msg+');"); which I believe is what you had. First the string concatenation doesn't look right and so I can understand why it doesn't work. I did try setInterval("change("+Msg+")"); but no good also. Thanks though.
 
R

Randy Webb

George said:
No one except my clumsy digits.

I tried it. I didn't work. Let me be nore specific:

Msg = "1<div>2<div>3<div>4<div>5<div>6"


change() just changes the visibility status of a div in the page.
When Msg="" then the div is hidden. When Msg<>"" then the div is visible.
So I did this:
setInterval("change('+Msg+');"); which I believe is what you had.
First the string concatenation doesn't look right and so I can
understand why it doesn't work. I did try setInterval("change("+Msg+")");
but no good also. Thanks though.

If you are checking the status of Msg, then let the change function do it.

function change(){
if (Msg != ""){
//Msg isn't empty, act accordingly
}
else{
//Msg is empty, act accordingly
}
}
 
G

George Hester

Yes that did it. I don't like the result. The div blinks. I think I can stop it but I'm not sure if that will be enough.
What is happening is I have a cube which rotates. The faces of the cube are links. When the mouse is over a face my div
pops up which shows the face's links in a more organized fashion. Without this div the loaction of where the links
are going to only shows in the status bar. What I want is the <div's child <divs to highlight corresponding to the
face the mouse is over. This cube is an applet and no I do not have permission to recompile or alter it.. I can only
use what I have and the author did not incorporate a way to use JavaScript in the Java applet. So what you've seen
is my idea.

I will setInterval on change (forms the div) onmouseover. Then I will have the innerHTML set one of the child <div's
with a class. That class will have style different then the other 5 divs. See that's my idea. Trouble is I get flicker.
Well back to the drawing board. Thanks for all your help.
 
I

Ivan Marsh

I tried it. I didn't work. Let me be nore specific:

Msg = "1<div>2<div>3<div>4<div>5<div>6"

change() just changes the visibility status of a div in the page. When
Msg="" then the div is hidden. When Msg<>"" then the div is visible.

So I did this:

setInterval("change('+Msg+');"); which I believe is what you had. First
the string concatenation doesn't look right and so I can understand why
it doesn't work. I did try setInterval("change("+Msg+")"); but no good
also.
Thanks though.

I assure you the PHP example I gave you works. I'm not sure if I got the
pure JavaScript example right.

Does your function work if it's not being called by setInterval? Make sure
the function itself works before you try to use setInterval because
debugging it inside setInterval is a nightmare.

Oop... wait a second... I just found an example I wrote that isn't
encapsulated in PHP:

<html>
<head>
<title>clock</title>
<script type='text/JavaScript'>
function GetTime(TimeAnchor) {
today = new Date();
TimeAnchor.innerHTML = today.toLocaleString(); delete today;
}
function UpdateTime(TimeAnchor) {
GetTime(TimeAnchor);
setInterval("GetTime(document.getElementById('" + TimeAnchor.id +
"'))", 1000);
}
</script>
</head>
<body>
<span id='DateTime'></span>
<script type='text/JavaScript'>
UpdateTime(document.getElementById("DateTime"));
</script>
</body>
</html>

This should print a running clock on the page (works in IE and Moz).
 
G

George Hester

Hey Ivan thanks for that. I think I can use your example in another area. The one I was trying
it doesn't look like it was a good idea. I cannot set the intveral to match with the active links. Being in a
applet it's not pleasant. I might still be able to use it using the changing status bar message but say la vie
for now.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Thu, 29
Jul 2004 17:34:33, seen in Ivan Marsh
setInterval("GetTime(document.getElementById('" + TimeAnchor.id +
"'))", 1000);
This should print a running clock on the page (works in IE and Moz).

I expect that you will find that it leaps over a second at intervals
dependent on the OS. See below.
 
I

Ivan Marsh

JRS: In article <[email protected]>, dated Thu, 29
Jul 2004 17:34:33, seen in Ivan Marsh



I expect that you will find that it leaps over a second at intervals
dependent on the OS. See below.

I'm not too worried about my clock being inacurate by a half-second every
five minutes.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Fri, 30
Jul 2004 15:32:10, seen in Ivan Marsh
I'm not too worried about my clock being inacurate by a half-second every
five minutes.

It is both untidy and easily avoided; and is some systems it will be
substantially more frequent.
 
I

Ivan Marsh

JRS: In article <[email protected]>, dated Fri, 30
Jul 2004 15:32:10, seen in Ivan Marsh


It is both untidy and easily avoided; and is some systems it will be
substantially more frequent.

Well, that's nice... but if you're not going to elaborate I really don't
care what you think it is. It doesn't do anyone any good for you to simply
point out code you don't like.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Mon, 2
Aug 2004 11:08:37, seen in Ivan Marsh
Well, that's nice... but if you're not going to elaborate I really don't
care what you think it is. It doesn't do anyone any good for you to simply
point out code you don't like.

Which part of the final sentence of my first contribution to this thread
- it was "See below." - did you have difficulty with?
 
I

Ivan Marsh

JRS: In article <[email protected]>, dated Mon, 2
Aug 2004 11:08:37, seen in Ivan Marsh


Which part of the final sentence of my first contribution to this thread
- it was "See below." - did you have difficulty with?

You might as well have simply posted a link to a javascript reference
manual.

Did you have an actual point about the code in question?
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Tue, 3
Aug 2004 10:38:13, seen in Ivan Marsh
You might as well have simply posted a link to a javascript reference
manual.

That does not answer my question. In effect, I did.
Did you have an actual point about the code in question?

Yes, that your clock will not display every second, which is inelegant.
By following the advice given you can find out why, and how easy it is
to prevent it. AISB, see below.
 
I

Ivan Marsh

Yes, that your clock will not display every second, which is inelegant.

I assure you it will, and does.

(This is where you say "no it won't and doesn't" but give no real reason
why or examples proving your claim.)
By following the advice given you can find out why, and how easy it is
to prevent it. AISB, see below.

As I said before, if YOU don't have something specific to say about the
code in question (as in code that will prevent the alleged problem) then
your opinion is pretty meaningless to me.
 
M

Michael Winter

Sorry to butt in, but...
I assure you it will, and does.

Looking at Dr Stockton's examples, there is a distinct difference between
their behaviour, though without logging in to my admin account, I can't
check which is the most "correct" in practice.

However, it should be noted that XP doesn't display the particular
characteristics that are required to display the problems (at as I
remember them, and the cause).
(This is where you say "no it won't and doesn't" but give no realreason
why or examples proving your claim.)


As I said before, if YOU don't have something specific to say aboutthe
code in question (as in code that will prevent the allegedproblem) then
your opinion is pretty meaningless to me.

A little exploration of Dr Stockton's site, in sensible locations, quickly
yields the information to which he refers. See:

<URL:http://www.merlyn.demon.co.uk/js-dates.htm#SPF>
<URL:http://www.merlyn.demon.co.uk/js-date0.htm#TaI>

Mike


Hoping the thread will end here.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Wed, 4
Aug 2004 10:33:57, seen in Ivan Marsh
I assure you it will, and does.

(This is where you say "no it won't and doesn't" but give no real reason
why or examples proving your claim.)

But you have given an example proving my claim; therefore, I don't need
to produce another. It misses showing about one second in 20 in Win98;
and I guess about one second in 100 in WinNT and similar.

Readily checked by adding +' '+K++ to your output, and initialising K.

Note : if you want it to work, with or without missing seconds, on more
browsers, then
move the initiating call of UpdateTime to be a Body OnLoad
supply a getElementById, such as can be found via below.

As I said before, if YOU don't have something specific to say about the
code in question (as in code that will prevent the alleged problem) then
your opinion is pretty meaningless to me.

But I do have something very specific to say; and the simplest way for
you to find it would be to follow the advice "See below". The regulars
here have mostly read it often enough already here.
 
D

Dr John Stockton

JRS: In article <opsb7yesaax13kvk@atlantis>, dated Wed, 4 Aug 2004
17:47:16, seen in Michael Winter <M.Winter@bl
ueyonder.co.invalid> posted :
However, it should be noted that XP doesn't display the particular
characteristics that are required to display the problems (at as I
remember them, and the cause).


It should be of interest to know the true timing resolution of different
systems - the resolution of new Date().

I believe that it is 55 ms in Win98 and earlier; 10 ms in WinNT and
later; WinME???. However, 1 ms has been asserted; but that may be due
to confusion with the resolution of the date object proper.

<URL:http://www.merlyn.demon.co.uk/js-dates.htm#OV> should show it for
the displaying system, just above the green-edged box.



<URL:http://www.merlyn.demon.co.uk/js-date0.htm#TaI>, in the last yellow
box, now shows the average interval obtained by setInterval(..., 1000),
which should also be of interest.

The previous yellow box shows ordinary and synchronised seconds counts,
using setTimeout.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top