473,513 Members | 2,665 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Issue w/ setTimeout

5 New Member
I'm trying to change the visibility of divs on a mouseover event. I have the script working that will do this, but when I try to use it with a setTimeout method, I cannot get it to work. My code is as follows:


function slide(name) {
setTimeout("display(name)", 1000);
}

function display(objname){

var caseNum;

if (objname == document.getElementById("illHeader")) {caseNum = 0;}
if (objname == document.getElementById("webHeader")) {caseNum = 1;}
if (objname == document.getElementById("mainHeader")) {caseNum = 2;}
if (objname == document.getElementById("flashHeader")) {caseNum = 3;}


switch(caseNum){
case 0: document.getElementById("ill").style.display = "block";
document.getElementById("web").style.display = "none";
document.getElementById("main").style.display = "none";
document.getElementById("flash").style.display = "none";
break;
case 1: document.getElementById("web").style.display = "block";
document.getElementById("ill").style.display = "none";
document.getElementById("main").style.display = "none";
document.getElementById("flash").style.display = "none";
break;
case 2: document.getElementById("main").style.display = "block";
document.getElementById("ill").style.display = "none";
document.getElementById("web").style.display = "none";
document.getElementById("flash").style.display = "none";
break;
case 3: document.getElementById("main").style.display = "none";
document.getElementById("ill").style.display = "none";
document.getElementById("web").style.display = "none";
document.getElementById("flash").style.display = "block";
break;
}
}

The html is as follows <div id="whatever" onmouseover="slide(this);">

I know there's probably a simple fix to this that's going to make me feel stupid, but at this point I'm willing to feel stupid as long as it works. Thanks!
Apr 20 '07 #1
1 1423
Logician
210 New Member
I'm trying to change the visibility of divs on a mouseover event. I have the script working that will do this, but when I try to use it with a setTimeout method, I cannot get it to work. My code is as follows:
Expand|Select|Wrap|Line Numbers
  1. function slide(name) {
  2.     setTimeout("display(name)", 1000);
  3. }
  4.  
name will be out of scope when display is called, which must be generating an error.
I would pass the id rather than a reference to the element:
Expand|Select|Wrap|Line Numbers
  1. <div id="main" onmouseover="slide(this.id);">content</div>
then
Expand|Select|Wrap|Line Numbers
  1. function slide(divId)
  2. {
  3.  setTimeout("display('"+divId+"')", 1000);
  4. }
Then display can be simplified to
Expand|Select|Wrap|Line Numbers
  1. function display(objId)
  2. {
  3.  var objRef=document.getElementById(objId);
  4.  
  5.  var divIds=["ill","web","main","flash"];
  6.  
  7.  for( var i=0, divRef; i<divIds.length; i++ )
  8.   (divRef=document.getElementById( divIds[i] ) ).style.display = (divRef==objRef ? 'block' : 'none' );
  9. }
I don't recommend the mouseover event for this operation.
Apr 21 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
14909
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
2
4632
by: Athanasius | last post by:
Could someone shed some light as to why the following setTimeout function will not work on the Mac IE5.2? It does however work on PC(Forefox,Netscape,IE) & Mac(Safari,Firefox). Here is the script,...
4
4764
by: hsonny | last post by:
Hi there, I have an ASP page using the treeview control from mscomctl.ocx that was running just fine. We updated our browsers with this package ( details at...
6
1742
by: daveyand | last post by:
Hey Guys, I've stumped. I created a function that does various things to select boxes. Namely Get All selected indexes, populate array with these values
6
2513
by: Nico VanHaaster | last post by:
Hello all, I have run across an issue with IE 6.0+. I have a page that makes an XMLHttpRequest to the webserver to update a report on the page. The first time you hit the refresh report button...
0
7157
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.