Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 7th, 2003, 08:30 AM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Function in a timer

Hi guys.

I have this problem where inside a function that is called when a onmouseout event occurs. In the function is a timer that calls another function after a delay.

First function:
function hideMenu(menuToHide)
{
 var srcElement = event.srcElement;
 if ((event.toElement != menuToHide) && (menuToHide.contains(event.toElement) == false))
 {
   setTimeout("slideMenu(" + menuToHide + ");",500);
 }
}

second function:
function slideMenu(menu)
{
    menu.style.left = -1000;
    menu.style.top = -200;
}

I plan to make the menu slide out of sight using DHTML, but at the moment i get "Error: 'object' is undefined" when i try running this.

If i pass a menu name directly into the function eg;
setTimeout("slideMenu(someMenuName);",500);

it works ok... but not when i have it as a variable.

Can anyone help with this please?


 
Old July 7th, 2003, 11:55 AM
Authorized User
 
Join Date: Jul 2003
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to stalker Send a message via MSN to stalker
Default

yap

I think your function is alrigth.. but the way you call the first function is wrong. make sure you send a valid argument to the first function.

in this little code below notice the event calling the function:
onload="doit('mostrar')"> (single quotes envolving the argument.
Take your necessary measures. if you post the code of the HTML element with the onmouseout event I could help more.

I tested your script with this code and it worked:

<html><head><title>teste</title><script>

function doit(id) {
  setTimeout("slideMenu(" + id + ");",500);
}

function slideMenu(menu) {
    menu.innerHTML = "worked"
}

</script>
</head><body onload="doit('mostrar')">
    <div id="mostrar"></div>
</body></html>

 
Old July 7th, 2003, 10:58 PM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In the body of the page the function is called like such:

<img src="images/but01.jpg" name="but01Img" id="but01Img" class="but01Img" onmouseover="return showMenu(infoMenuDiv)" onmouseout="return hideMenu(infoMenuDiv)">

I have several button images and the usual method of onmouseover a menu appears and on mouseout menu disappears..

I did what you suggested and placed ' ' around the infoMenuDiv in the onmouseover/out and that caused a problem elsewhere.
I got a "Error: style is null or not an object" on the line:

menuToShow.style.left = xPos + (srcElement.width);



 
Old July 8th, 2003, 12:59 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I would change the function thus:
Code:
function slideMenu(menu)
{
    var oMenu = document.getElementById(menu);
    oMenu.style.left = -1000;
    oMenu.style.top = -200;
}
and then change the first one to read:
Code:
  setTimeout("slideMenu('" + menuToHide.id + "');",500);
Parameters need to be in global scope if they are variables.

Why are you setting srcElement in the other function and not using it

--

Joe
 
Old July 8th, 2003, 01:29 AM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok all sorted... thanks guys.

Typical that i figured out what i was doing wrong then came on here and found the answer waiting :)

As for the srcElement, that is for another feature that wasn't relevant so i deleted it to save posting huge lines of text in here, but i guess i missed that part. My bad.

Thanks again guys... im well chuffed with the end result.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Countdown Timer stalkingbutler Access VBA 2 April 16th, 2007 10:44 AM
Timer Dhanapal ADO.NET 2 April 16th, 2007 04:58 AM
Help with Timer and BackgroundWorker lukaszt C# 0 February 1st, 2007 10:25 AM
Timer prasanta2expert Access VBA 1 November 8th, 2006 09:28 AM
timer amerei ASP.NET 1.0 and 1.1 Professional 0 October 15th, 2005 10:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.