1

Topic: [JAVASCRIPT DOM] Problem with SetTimeOut

Here's my script

count=1;
function drop(id,display) {
    clearTimeout(count);
    document.getElementById(id).style.display=display;
}

function dropoff(id,display) {
    count=setTimeout("document.getElementById(id).style.display=display",1000);
}

my function is called like that :

<a href="url.htm" onmouseover="drop('test2','block')" onmouseout="dropoff('test2','none')">Test Show/Hide Menu</A>

And of course, a div with id = test 2

<div id="test2">Blablablablabla</div>

When I onmouseover, if the div test is display : none ... I have no problem : the div appears ... but in mouseout, there is a bug with settimeout which says "ID is undefined" ...

Has someone has an idea (I could of course give the name inside the script of the ID of the DIV, but I want to have SEVERAL menus)

2 (edited by Serge 2005-01-21 13:30)

Re: [JAVASCRIPT DOM] Problem with SetTimeOut

try doing:

count=setTimeout("document.getElementById('"+id+"').style.display=display",1000);

... instead. Otherwise, the variable "id" won't be evaluated until the expression is executed (1000 ms later) - and since it's not global, but a function argument, that means it'll be undefined at that time. This way, the variable name is replaced with 'test2' (including start and end singlequotes).

3

Re: [JAVASCRIPT DOM] Problem with SetTimeOut

Thanx a lot Serge !!!

I have another question

I want my layout appears and disappears when I onmouseover/onmouseout on it ... it's the case on the code I have sent.

But I want during this delay (1000 ms), if someone goes ON the DIV, it stays !

I have tested

<div id="test2" onmouseover="drop('test2','block')" onmouseout="dropoff('test2','none')">Blalablala</div>

But in spite of putting the onmouseover, the LAYER disappears !!! sad

And of course, If I have 1, 2 or 10 menus, it would be the same thing ...

Have you a solution ?