473,666 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Popup menu problems

I'm having problems getting my popup menu to work correctly, and was
hoping someone here could point me in the right direction. I have the
following script:

<script>
var activeMenu="";

function getObject(id) {
var object=eval("do cument.getEleme ntById('"+id+"' )");
return object;
}

function PopMenu(M) {
clearTimeout();
HideActive();
getObject(M).st yle.visibility= "visible";
activeMenu=M;
}

function HideActive() {
if (activeMenu !="") {
getObject(activ eMenu).style.vi sibility="hidde n";
activeMenu="";
}
}

function menuTimeout() {
setTimeout("Hid eActive()", 2000);
}
</script>

which goes with the following html:

<div id="menuhead" onMouseOver="Po pMenu('menu')">
<img src="menuhead.g if" />
</div>
<div id="menu" onMouseOut="men uTimeout()">
<a href="test1.htm ">Test 1</a>
<a href="test2.htm ">Test 2</a>
<a href="test3.htm ">Test 3</a>
</div>
The menu opens perfectly, but it closes 2 sec after I mouseOut() of
'menuhead' instead of the actual 'menu'. Also, if I repeatly
mouseOver() the 'menuhead', the timing gets thrown off, as if
clearTimeout() is being called irregularly. Could someone with more
experience give me a hand?

Thanks,
Aaron

Jul 23 '05 #1
5 3241
Aaron wrote:
I'm having problems getting my popup menu to work correctly, and was
hoping someone here could point me in the right direction. I have the
following script:


Here's an alternative approach:

<style type="text/css">
#menu {
position: absolute;
clip: rect(auto auto 15px auto)
}
</style>
....
<div id="menu"
onmouseout="sty le.clip='rect(a uto auto 15px auto)'"
onmouseover="st yle.clip='rect( auto auto auto auto)'">
Show menu<br />
<a href="test1.htm ">Test 1</a>
<a href="test2.htm ">Test 2</a>
<a href="test3.htm ">Test 3</a>
</div>
JW

Jul 23 '05 #2
Here's an alternative approach:

<style type="text/css">
#menu {
position: absolute;
clip: rect(auto auto 15px auto)
}
</style>
...
<div id="menu"
onmouseout="sty le.clip='rect(a uto auto 15px auto)'"
onmouseover="st yle.clip='rect( auto auto auto auto)'">
Show menu<br />
<a href="test1.htm ">Test 1</a>
<a href="test2.htm ">Test 2</a>
<a href="test3.htm ">Test 3</a>
</div>


This works great...thanks so much, JW. Now, to get the setTimeout(),
I've changed it to the following:

<style type="text/css">
#menu {position: absolute;
clip: rect(auto auto 15px auto);
}
</style>
<script type="text/javascript">
function getObject(id) {
var object=eval("do cument.getEleme ntById('"+id+"' )");
return object;
}
function openMenu(id) {
var name=getObject( id);
name.style.clip ='rect(auto auto auto auto)';
}
function closeMenu(id) {
var name=getObject( id);
name.style.clip ='rect(auto auto 15px auto)';
}
function menuTimeout(id) {
setTimeout("clo seMenu(id)", 2000);
}
</script>
<div id="menu" onmouseout="men uTimeout('menu' )"
onmouseover="op enMenu('menu')" >
<p>Show menu</p>
<ul>
<li><a href="test1.htm ">Test 1</a></li>
<li><a href="test2.htm ">Test 2</a></li>
<li><a href="test3.htm ">Test 3</a></li>
</ul>
</div>

Passing the id name to the menuTimeout() function doesn't seem to work
at all. What am I doing wrong here?

Thanks,
Aaron
Jul 23 '05 #3
Aaron <ag********@com cast.not> writes:
I'm having problems getting my popup menu to work correctly, and was
hoping someone here could point me in the right direction. I have the
following script:
I'll try to give some suggestions that you can try.
<script>
The "type" attribute is required in HTML.
<script type="text/javascript">
var activeMenu="";

function getObject(id) {
var object=eval("do cument.getEleme ntById('"+id+"' )");
You *never* need to use eval for accessing elements by name. You
probably never need to use eval at all, and shouldn't, since there are
more efficient and less error prone alternatives. This function can
just be written:

return document.getEle mentById(id);
return object;
}

function PopMenu(M) {
clearTimeout();
The function "clearTimeo ut" takes an argument: the value returned by
the call to setTimeout that you want to cancel.
<URL:http://www.mozilla.org/docs/dom/domref/dom_window_ref8 .html#1016919>
<URL:http://msdn.microsoft. com/workshop/author/dhtml/reference/methods/cleartimeout.as p>

Make a global variable outside the function,
var timeout_id;
and call
clearTimeout(ti meout_id);
timeout_id = null;
and set it again when you call setTimeout.
HideActive();
getObject(M).st yle.visibility= "visible";
activeMenu=M;
}

function HideActive() {
if (activeMenu !="") {
getObject(activ eMenu).style.vi sibility="hidde n";
activeMenu="";
}
}

function menuTimeout() {
setTimeout("Hid eActive()", 2000);
first clear the existing timeout, if any:
if (timeout_id != null) { clearTimeout(ti meout_id); }
This avoids having two timeouts running at the same time,
when you can only cancel one.

and then start a new countdown:
timeout_id = setTimeout("Hid eActive()",2000 ):
(or even
timeout_id = setTimeout(Hide Active, 2000);
in modern browsers)
}
</script>

which goes with the following html:

<div id="menuhead" onMouseOver="Po pMenu('menu')">
<img src="menuhead.g if" />
You should not write "/>" in HTML. It is only for XHTML, which you
don't seem to use (attribute names are all lower case in XHTML).
The menu opens perfectly, but it closes 2 sec after I mouseOut() of
'menuhead' instead of the actual 'menu'.
Not for me. When I try your code in IE 6 (without the image :),
the submenu starts visible. When I put the mouse over it and leaves
again, the submenu disappears after two seconds (even if I am, at that
point, over the menuhead ... most likely because clearTimeout fails to
do anything).
Also, if I repeatly
mouseOver() the 'menuhead', the timing gets thrown off, as if
clearTimeout() is being called irregularly.


clearTimeout, as you call it, does nothing, so every mouseout will
schedule a hide, with the only limit to how many you can have pending
being how fast you can twiddle your moust.

Good luck.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #4
Aaron <ag********@com cast.not> writes:
<style type="text/css">
#menu {position: absolute;
clip: rect(auto auto 15px auto);
I would recommend changing "15px" to "1.2em" (or whatever the line
height is). To see why, try adding:
font-size: large;
That can happen to people with different default font settings too.
function menuTimeout(id) {
setTimeout("clo seMenu(id)", 2000);


This won't work. The code
closeMenu(id)
will be executed in the global context, and will not have access
to the local variables of the menuTimeout function, including "id".

You can either use:
setTimeout("clo seMenu('"+id+"' );", 2000);
(i.e., build the id into the expression as a string literal) or
setTimeout(func tion(){closeMen u(id);}, 2000);
(use a closure to capture the value of "id").

See my other reply for other suggestions.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #5
Thanks for help, Lasse. Works great now.

Aaron

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4365
by: Moon | last post by:
Seems I still haven't got the hang of all those window generating code in Javascript. I've got a page with about 15 photo thumbnails. When you click on a thumbnail a new window pops up which shows the enlarged version of said thumbnail. This works fine on all current browsers I've tested. However, in case I do not close the popup but click on another thumbnail instead, only IE replaces the enlarged pic by the new one, Firebird and Opera...
3
3964
by: Uwe Range | last post by:
Hi to all, I am displaying a list of records in a subform which is embedded in a popup main form (in order to ensure that users close the form when leaving it). It seems to be impossible to delete a record in this subform. When I switched modal off and tried to delete a record from the list, I deleted a record on another form (below the popup form).
2
5861
by: PC User | last post by:
I'm creating a shortcut menu to popup over my richtext box. Its a form with a listbox of menu items with associated richtext activex (rtf) editing commands. I found a way to transfer a value from the popup menu to the form, but now I have one more step to take. The value being transferred is a public function from a module. I need to find a way to execute the function to edit the text in the richtext field. Download the test database from...
2
1979
by: ouech | last post by:
hi, i finally tryied with a popup menu but i have a problem. i popup it with TrackMenuPopup and i create it from a ressource. but it doesn't look as it should. i d'ont have the names of the menu categories, only a small rect appears but with nothing wrote in. when i pass on with the cursor, it popup the sub-menu quite far from the small rect, but the submenu is good looking.
2
1845
by: SamSpade | last post by:
I use to get popup events when I checked out the menu coding. That was a while ago. Something I did in the interim must have suppressed those events because I just noticed I don't get them any more. What could I do that will cause menu item Popup events not to be raised? I've been looking but really don't know where to look anymore. Second question. A control has a context menu.
7
3660
by: anthony.turcotte | last post by:
Hi, I've looked for a solution to this problem on google, read posts in this newsgroup and I still haven't found anything that could help me. Here's the scenario. 1. User accesses pageA.html 2. User clicks on menu link to open popup.html 3. pageA.html checks if popup.html is already open. It is not, open
9
7869
by: john | last post by:
In Paradox I was able to create popup menu's in which some of the items had popup menu's themselves. I've looked for threads on popup menu's and access but I can't find how to make a simple popup menu. The popup menu I want to make should appear when I rightclick a button on my form. A user's choice should do some action. Can someone point me in the right direction? thanks, john
1
1116
by: =?Utf-8?B?Q2hyaXN0aWFuIEphY29i?= | last post by:
Hi everyone, I created a web application which presents a menu based on a sitemap. The menu entries are rendered using a Repeater with HyperLink controls as shown in the data tier tutorials on www.asp.net. So that the sub-pages are opened in own popup windows (i.e. without toolbar, navigationbar, etc.), the links refer to a javascript which basically does a window.open with all necessary settings. Also, all pages contain a...
2
3260
by: wreed06 | last post by:
Hello, I have 2 problems. In my webpage, I have a dropdown list with a button that takes the user to a popup window specific to the option. I am using Firefox 2.0.0.13. I have successfully validated my HTML and CSS code. 1. When I clear cache and refresh my webpage, it takes 3 tries before the popup window displays - I click on the button once, a white window the size of my webpage displays. I close it and click on the button again (for...
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8355
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.