Toggling display problems

J

Jamie

Hi all,

I have a page in which I display a menu which is a table within a div
element. Each cell in the table is a menu item with an "onclick" event
handler assigned.

I want to make it so that whenever the user clicks outside of the menu, the
menu is hidden. The only way I can see of doing this is using the
"ondeactivate" event for the table/div, but whenever I handle this event it
swallows the "onclick" event for the menu items, rendering the menu useless.

Is there an easier way of doing this? Any help would be much appreciated.

Cheers,

Jamie
 
N

Nik Coughin

Jamie said:
Hi all,

I have a page in which I display a menu which is a table within a div
element. Each cell in the table is a menu item with an "onclick" event
handler assigned.

I want to make it so that whenever the user clicks outside of the
menu, the menu is hidden. The only way I can see of doing this is
using the "ondeactivate" event for the table/div, but whenever I
handle this event it swallows the "onclick" event for the menu items,
rendering the menu useless.

Is there an easier way of doing this? Any help would be much
appreciated.

Cheers,

Jamie

I don't get what you mean. Do you mean that you want a menu which is
visible until you click elsewhere, and then it disappears completely? Or do
you mean that the items in the menu are only visible if the menu has focus,
but it has a header or something at the top that is always visible so that
you can click it to give the menu focus and show the menu items, that sort
of thing?
 
N

Nik Coughin

Do you have a URL as an example of what you are trying to do or have done so
far?
 
J

Jamie

Nik Coughin said:
I don't get what you mean. Do you mean that you want a menu which is
visible until you click elsewhere, and then it disappears completely? Or do
you mean that the items in the menu are only visible if the menu has focus,
but it has a header or something at the top that is always visible so that
you can click it to give the menu focus and show the menu items, that sort
of thing?

Hi Nik,

I have a menu that is displayed when a user right clicks on an image. I want
the menu to disappear when the user clicks outside of the menu. The only
ways I've tried so far - "ondeactivate" and "onblur" - seem to swallow the
click event for the menu cells.

Cheers,

Jamie
 
N

Nik Coughin

Jamie said:
Hi Nik,

I have a menu that is displayed when a user right clicks on an image.
I want the menu to disappear when the user clicks outside of the
menu. The only ways I've tried so far - "ondeactivate" and "onblur" -
seem to swallow the click event for the menu cells.

Cheers,

Jamie

You mean like this?
http://javascript.internet.com/page-details/right-click-menu.html

You can see other scripts that do the same here:
http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=javascript+right+click+menu&spell=1

Remember that Macs don't have a right mouse button. I'm not sure if it is
possible or not to fire a right mouse button event from a Mac browser, I
don't have one to test it in.
 
N

Nik Coughin

Mark said:
Let's hope not. For starters, it only works in IE, so if that is your
only method of navigation, users of other browsers won't be able to
get past the first page. Second, it won't work at all for anyone if
they have Javascript disabled. Third, it removes all the normal
right-click menu options, probably pissing off a lot of your visitors.

All good points. That script doesn't do quite what you want it to do
anyway, but you can learn the techniques that you need in order to do what
you want to do by looking through their code. It definitely isn't the
optimal way to have a menu for an image though, for the reasons outlined
above.

Maybe you could have a menu icon or something alongside the image, that when
clicked on or mouseovered brings up a menu. I think that you could do it in
CSS using the hover pseudoclass, but I seem to recall that hover only works
for anchor elements in IE (it's supposed to work with any element, but what
do you do).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top