Reset setTimeout

M

Mike

Hey,

I posted a question yesterday that was pretty confusing. I've figured
out some of it for myself, but there's still one issue that I can't
figure out, and I've been trying for months now!

I have a pop-up menu; one of those where you scroll over the menu, and
a submenu pops up beneath it. Everything's running smoothly on every
browser I've tested with, except for one problem on every browser: the
"clearing" of the menu.

The menu itself is being called by:
onMouseOver="menu(1)" onMouseOut="clearIt()"

function menu(x) let's "x" refer to a predefined array, which
determines which menu to pop up. That menu is stored in a variable,
showMenu. If x==0, then it changes showMenu to a whitespace, thus
"clearing" the submenu altogether.


clearIt() is a simple function, pasted here:
function clearIt() { setTimeout("menu('0')", 7000) }

The idea is that the menu will disappear after 7 seconds. The problem
I'm having, though, is that the 7 seconds starts after the first
onMouseOut, and doesn't restart when the visitor mouses over the
second button. So, if I look at the first submenu for 6 seconds, then
when I go to the second button the menu only stays open for 1 second,
instead of starting the timer over.

Is there any way to reset this timer? I know it can be done, since
editors seem to be able to do it, but I can't find any reference to it
on Google.

TIA,

Mike
 
E

Evertjan.

Mike wrote on 07 sep 2003 in comp.lang.javascript:
function clearIt() { setTimeout("menu('0')", 7000) }

The idea is that the menu will disappear after 7 seconds. The problem
I'm having, though, is that the 7 seconds starts after the first
onMouseOut, and doesn't restart when the visitor mouses over the
second button. So, if I look at the first submenu for 6 seconds, then
when I go to the second button the menu only stays open for 1 second,
instead of starting the timer over.

Is there any way to reset this timer? I know it can be done, since
editors seem to be able to do it, but I can't find any reference to it
on Google.


mytimeout = setTimeout("menu('0')", 7000)

clearTimeout(mytimeout)

<http://msdn.microsoft.com/
workshop/author/dhtml/reference/methods/cleartimeout.asp>
 

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
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top