By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,645 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,645 IT Pros & Developers. It's quick & easy.

setInterval(F(x));

P: n/a
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.

--
George Hester
__________________________________
Jul 23 '05 #1
Share this Question
Share on Google+
17 Replies


P: n/a
On Thu, 29 Jul 2004 20:02:31 +0000, George Hester wrote:
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.getElementBy Id('\" + 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.
--
i.m.
The USA Patriot Act is the most unpatriotic act in American history.

Jul 23 '05 #2

P: n/a
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.

--
George Hester
__________________________________
"Ivan Marsh" <an*****@you.now> wrote in message news:pa**************************@you.now...
On Thu, 29 Jul 2004 20:02:31 +0000, George Hester wrote:
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.getElementBy Id('\" + 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.


--
i.m.
The USA Patriot Act is the most unpatriotic act in American history.

Jul 23 '05 #3

P: n/a
George Hester wrote:
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
}
}
Jul 23 '05 #4

P: n/a
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.

--
George Hester
__________________________________
"Randy Webb" <Hi************@aol.com> wrote in message news:a4********************@comcast.com...
George Hester wrote:
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
}
}

Jul 23 '05 #5

P: n/a
On Thu, 29 Jul 2004 20:46:14 +0000, George Hester wrote:
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).

--
i.m.
The USA Patriot Act is the most unpatriotic act in American history.

Jul 23 '05 #6

P: n/a
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.

--
George Hester
__________________________________
"Ivan Marsh" <an*****@you.now> wrote in message news:pa****************************@you.now...
On Thu, 29 Jul 2004 20:46:14 +0000, George Hester wrote:
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).

--
i.m.
The USA Patriot Act is the most unpatriotic act in American history.

Jul 23 '05 #7

P: n/a
JRS: In article <pa****************************@you.now>, dated Thu, 29
Jul 2004 17:34:33, seen in news:comp.lang.javascript, Ivan Marsh
<an*****@you.now> posted :
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.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #8

P: n/a
On Fri, 30 Jul 2004 15:59:59 +0100, Dr John Stockton wrote:
JRS: In article <pa****************************@you.now>, dated Thu, 29
Jul 2004 17:34:33, seen in news:comp.lang.javascript, Ivan Marsh
<an*****@you.now> posted :
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'm not too worried about my clock being inacurate by a half-second every
five minutes.

--
i.m.
The USA Patriot Act is the most unpatriotic act in American history.

Jul 23 '05 #9

P: n/a
JRS: In article <pa****************************@you.now>, dated Fri, 30
Jul 2004 15:32:10, seen in news:comp.lang.javascript, Ivan Marsh
<an*****@you.now> posted :
On Fri, 30 Jul 2004 15:59:59 +0100, Dr John Stockton wrote:
JRS: In article <pa****************************@you.now>, dated Thu, 29
Jul 2004 17:34:33, seen in news:comp.lang.javascript, Ivan Marsh
<an*****@you.now> posted :
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'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.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 23 '05 #10

P: n/a
On Sat, 31 Jul 2004 13:12:24 +0100, Dr John Stockton wrote:
JRS: In article <pa****************************@you.now>, dated Fri, 30
Jul 2004 15:32:10, seen in news:comp.lang.javascript, Ivan Marsh
<an*****@you.now> posted :
On Fri, 30 Jul 2004 15:59:59 +0100, Dr John Stockton wrote:
JRS: In article <pa****************************@you.now>, dated Thu,
29 Jul 2004 17:34:33, seen in news:comp.lang.javascript, Ivan Marsh
<an*****@you.now> posted :

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'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.


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.

--
i.m.
The USA Patriot Act is the most unpatriotic act in American history.

Jul 23 '05 #11

P: n/a
JRS: In article <pa***************************@you.now>, dated Mon, 2
Aug 2004 11:08:37, seen in news:comp.lang.javascript, Ivan Marsh
<an*****@you.now> posted :
On Sat, 31 Jul 2004 13:12:24 +0100, Dr John Stockton wrote:
JRS: In article <pa****************************@you.now>, dated Fri, 30
Jul 2004 15:32:10, seen in news:comp.lang.javascript, Ivan Marsh
<an*****@you.now> posted :
On Fri, 30 Jul 2004 15:59:59 +0100, Dr John Stockton wrote:
JRS: In article <pa****************************@you.now>, dated Thu,
29 Jul 2004 17:34:33, seen in news:comp.lang.javascript, Ivan Marsh
<an*****@you.now> posted :

> 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'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.


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?

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #12

P: n/a
On Mon, 02 Aug 2004 20:26:14 +0100, Dr John Stockton wrote:
JRS: In article <pa***************************@you.now>, dated Mon, 2
Aug 2004 11:08:37, seen in news:comp.lang.javascript, Ivan Marsh
<an*****@you.now> posted :
On Sat, 31 Jul 2004 13:12:24 +0100, Dr John Stockton wrote:
JRS: In article <pa****************************@you.now>, dated Fri,
30 Jul 2004 15:32:10, seen in news:comp.lang.javascript, Ivan Marsh
<an*****@you.now> posted :
On Fri, 30 Jul 2004 15:59:59 +0100, Dr John Stockton wrote:
> JRS: In article <pa****************************@you.now>, dated
> Thu, 29 Jul 2004 17:34:33, seen in news:comp.lang.javascript, Ivan
> Marsh <an*****@you.now> posted :
>
>> 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'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.


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?


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?
--
i.m.
The USA Patriot Act is the most unpatriotic act in American history.

Jul 23 '05 #13

P: n/a
JRS: In article <pa****************************@you.now>, dated Tue, 3
Aug 2004 10:38:13, seen in news:comp.lang.javascript, Ivan Marsh
<an*****@you.now> posted :
On Mon, 02 Aug 2004 20:26:14 +0100, Dr John Stockton wrote:
JRS: In article <pa***************************@you.now>, dated Mon, 2
Aug 2004 11:08:37, seen in news:comp.lang.javascript, Ivan Marsh
<an*****@you.now> posted :
On Sat, 31 Jul 2004 13:12:24 +0100, Dr John Stockton wrote:

JRS: In article <pa****************************@you.now>, dated Fri,
30 Jul 2004 15:32:10, seen in news:comp.lang.javascript, Ivan Marsh
<an*****@you.now> posted :
>On Fri, 30 Jul 2004 15:59:59 +0100, Dr John Stockton wrote:
>> JRS: In article <pa****************************@you.now>, dated
>> Thu, 29 Jul 2004 17:34:33, seen in news:comp.lang.javascript, Ivan
>> Marsh <an*****@you.now> posted :
>>
>>> 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'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.

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?


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.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #14

P: n/a
On Tue, 03 Aug 2004 21:18:31 +0100, Dr John Stockton wrote:
Did you have an actual point about the code in question?
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.
Jul 23 '05 #15

P: n/a
On Wed, 04 Aug 2004 10:33:57 -0500, Ivan Marsh <an*****@you.now> wrote:

Sorry to butt in, but...
On Tue, 03 Aug 2004 21:18:31 +0100, Dr John Stockton wrote:
Did you have an actual point about the code in question?
Yes, that your clock will not display every second, which isinelegant.


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.)
By following the advice given you can find out why, and how easyit is
to prevent it. AISB, see below.


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.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail
Jul 23 '05 #16

P: n/a
JRS: In article <pa****************************@you.now>, dated Wed, 4
Aug 2004 10:33:57, seen in news:comp.lang.javascript, Ivan Marsh
<an*****@you.now> posted :
On Tue, 03 Aug 2004 21:18:31 +0100, Dr John Stockton wrote:
Did you have an actual point about the code in question?


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.)


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.

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.


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.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #17

P: n/a
JRS: In article <opsb7yesaax13kvk@atlantis>, dated Wed, 4 Aug 2004
17:47:16, seen in news:comp.lang.javascript, 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.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.