Solved

reset setTimeout

Posted on 2002-03-17
3
2,219 Views
Last Modified: 2012-06-27
I am using this javascript code:

function delayhidemenu() {
     setTimeout("hideall()",5000)
}

This code will hide some html code after 5 seconds.
It works fine.

But is it possible to reset/disable the settimeout after it has been set. I use the code when I move the mouse from a link -> like this: onmouseout="delayhidemenu()".

However when I go over the link again in the 5 seconds the html text will be still hidden after the 5 seconds!
That is not what I want it to be!

Can this be done?
0
Comment
Question by:draco51
  • 3
3 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 6874399
set your timeout like this:


   var myTimoutID = setTimeout("hideall()",5000);



then clear it like this:

   clearTimeout(myTimoutID);

0
 
LVL 33

Expert Comment

by:knightEknight
ID: 6874404
... just make sure that the variable myTimeoutID is global in scope (i.e., not local to the function that calls setTimeout).
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 200 total points
ID: 6874422
like this:


var myTimeoutID;

function delayhidemenu() {
    if (myTimeoutID)
       clearTimeout(myTimeoutID);
    myTimeoutID = setTimeout("hideall()",5000);
}
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question