473,748 Members | 6,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

position absolute does not go above a dropdown (<select>...)

I'm using the code below to display a menu that opens when the mouse
goes over the main menu item (try it in your browser to understand the
behaviour).

It uses "position:absol ute" and a switch between "display='none' " and
"display='' ".

However the problem is that
- in Internet Explorer 6 the dropdown (<select>...) always hides the
menu
- in Mozilla the menu is hidden initially but after clicking on the
text "Select" it isn't hidden.

How does that come and how can I overcome it?
I want the menu to be above the other stuff when it comes up.

Regards,
Joachim
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<head>
<title>Menu Example</title>
</head>
<body>
<form method="get" action="target. jsp" name="myForm">
<TABLE id="acGeneralMa inMenuItem" border="1" rules="none"
cellspacing="0" bordercolor="bl ue">
<TR class="tableMen uRow">
<TD NOWRAP ONMOUSEOVER="sh owSubmenu('acGe neralSubmenu',t his,'acGeneralM ainMenuItem');"
ONMOUSEOUT="hid eSubmenu('acGen eralSubmenu');" >
&nbsp;Genera l menu&nbsp;<br>
<TABLE id="acGeneralSu bmenu"
border="1" rules="none" cellspacing="0" bordercolor="bl ue"
style="display: none; position:absolu te;">
<TR class="tableMen uRow">
<TD NOWRAP id="generalMenu Item0" onclick=
"document.getEl ementsByTagName ('form')[0].actionSelected .value='f158';d ocument.getElem entsByTagName(' form')[0].submit()"

ONMOUSEOVER="hi ghlightMenuItem ('generalMenuIt em0');"

ONMOUSEOUT="low lightMenuItem(' generalMenuItem 0');">
&nbsp;Genera l item 1&nbsp;
</TD>
</TR>
<TR class="tableMen uRow">
<TD NOWRAP id="generalMenu Item1"
onclick="docume nt.getElementsB yTagName('form' )[0].actionSelected .value='f159';d ocument.getElem entsByTagName(' form')[0].submit()"
ONMOUSEOVER="hi ghlightMenuItem ('generalMenuIt em1');"
ONMOUSEOUT="low lightMenuItem(' generalMenuItem 1');">
&nbsp;Genera l item 2&nbsp;
</TD>
</TR>
<TR class="tableMen uRow">
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<p>
<input type="hidden" name="actionSel ected" value="">
Select
<SELECT name="f145">
<OPTION value="*" selected>*</OPTION>
<OPTION value="option1" >option1</OPTION>
<OPTION value="option2" >option2</OPTION>
<OPTION value="option3" >option3</OPTION>
<OPTION value="option4" >option4</OPTION>
<OPTION value="option5" >option5</OPTION>
<OPTION value="option6" >option6</OPTION>
<OPTION value="option7" >option7</OPTION>
<OPTION value="option8" >option8</OPTION>
<OPTION value="option9" >option9</OPTION>
</SELECT>
</form>


<script type="text/javascript">
<!--
// Define a global variable to hold the id of the submenu showed the
last time
var lastSubmenuShow n='';

// Define a function to show the submenu at an absolute position
relative to
// the main menu item's position within the parent element.
// The structure of the main menu item and the submenu is:
// <TABLE id="acGeneralMa inMenuItem" ...>
// <TR ...>
// <TD NOWRAP ONMOUSEOVER="sh owSubmenu('acGe neralSubmenu',t his,'acGeneralM ainMenuItem');"
// ONMOUSEOUT="hid eSubMenu('acGen eralSubmenu')">
// General Actions<br>
// <TABLE id="acGeneralSu bmenu" style="display: none;
position:absolu te;"
// <TR ...>
// <TD NOWRAP id="..."
// ONCLICK="script to execute action associated with
submenu item"
// ...
// >Action1</TD>
// ...
//
// Parameters:
// submenuId: the id of the submenu to be shown
// parent: the parent of the main menu item
// mainMenuItemId: the id of the main menu item
function showSubmenu(sub menuId,parent,m ainMenuItemId)
{ // Hide last submenu
if (lastSubmenuSho wn!='') hideSubmenu(las tSubmenuShown);

// Initialize yOffset with the height of the main menu item minus 2
var yOffset=documen t.getElementByI d(mainMenuItemI d).offsetHeight-2;
var x = 0;
var y = yOffset;
do {
x += parent.offsetLe ft;
y += parent.offsetTo p;
} while ( parent = parent.offsetPa rent );

var e = document.getEle mentById( submenuId );
e.style.left = x + 'px';
e.style.top = y + 'px';
e.style.display = '';
var xMax = document.body.s crollLeft + document.body.c lientWidth;
if ( x + e.clientWidth > xMax ) {
e.style.left = ( xMax > e.clientWidth ?
( xMax - e.clientWidth ) : 0 ) + 'px';
}

if ( y + e.clientHeight > document.body.s crollTop +
document.body.c lientHeight ) {
y -= e.clientHeight + ( yOffset ? yOffset : 0 );
e.style.top = ( y > e.clientHeight ? y : 0 ) + 'px';
}

lastSubmenuShow n=submenuId;

return false;
}

// Define a function to hide the submenu
// Parameters:
// submenuId: the id of the submenu to be hidden
function hideSubmenu(sub menuId)
{ document.getEle mentById(submen uId).style.disp lay = 'none';
return false;
}

// Define a variable to hold the id of the last menu item highlighted
var lastHighlighted Menu='';

// Define a function to highlight a menu item
function highlightMenuIt em(menuItemId)
{ if (lastHighlighte dMenu!='') lowlightMenuIte m(lastHighlight edMenu);
document.getEle mentById(menuIt emId).setAttrib ute('bgcolor',' #aaaaff','false ');
lastHighlighted Menu=menuItemId ;
}

// Define a function to lowlight a menu item
function lowlightMenuIte m(menuItemId)
{ document.getEle mentById(menuIt emId).setAttrib ute('bgcolor',' white','false')
}
//-->
</script>
</body>
</HTML>
Jul 23 '05 #1
2 6438
Joachim Bauer wrote:
I'm using the code below to display a menu that opens when the mouse
goes over the main menu item (try it in your browser to understand the
behaviour).

It uses "position:absol ute" and a switch between "display='none' " and
"display='' ".

However the problem is that
- in Internet Explorer 6 the dropdown (<select>...) always hides the
menu
<select> is the only remaining windowed element, it is always positioned over other elements.

<url: http://support.microsoft.com/default...b;en-us;177378 />
- in Mozilla the menu is hidden initially but after clicking on the
text "Select" it isn't hidden.
By default the background-color of the table is probably "transparen t". Changing the style definition from:
style="display: none; position:absolu te;
to
style="display: none; position:absolu te;background-color:white;"

Seemed to resolve the problem. Also, you probably shouldn't be using setAttribute() and "bgcolor". You'd be far better off changing:

document.getEle mentById(menuIt emId).setAttrib ute('bgcolor',' white','false')
to:
document.getEle mentById(menuIt emId).style.bac kgroundColor = 'white';

And when setAttribute() does take a 3rd parameter, it is supposed to be an integer, not a string. By passing the string 'false', it
evaluates to true so you're actually passing the opposite value to what you are intending. More on setAttribute() at <url:
http://msdn.microsoft.com/workshop/a...tattribute.asp />, but as I said, you'd be better off using
..style.backgro undColor = ...
How does that come and how can I overcome it?
I want the menu to be above the other stuff when it comes up.


Defining a background-color on the table style seems to resolve the problem in Gecko-based browsers, but in IE, there is no way of
keeping a <select> from appearing on top of every other element.

--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq

Jul 23 '05 #2
Grant, thanks for your hints. I wrote a workaround for I.E.'s stupid
behaviour to keep <select> above everything else. It is hiding all
<select>s that overlap with my menus. It is done with the function
below which is called in showSubmenu and in hideSubMenu in case of
navigator.appNa me is "Microsoft Internet Explorer".

// Define a function to show/hide the select controls
// that overlap with the menu
// Parameters:
// actions: may be 'hide' of 'show'
// x: the x position of the menu
// y: the y position of the menu
// width: the width of the menu
// height: the height of the menu
function showHideSelectC ontrols(action, x,y,width,heigh t)
{ var right=x+width-1;
var bottom=y+height-1;

var selectControls= document.getEle mentsByTagName( "select");
for (var i=0; i<selectControl s.length; i++)
{ if (action=='hide' )
{ var sx=selectContro ls[i].offsetLeft;
var sy=selectContro ls[i].offsetTop;

// sx and sy are relative to parent. Compute absolute values
var parent=selectCo ntrols[i].offsetParent;
do {
sx += parent.offsetLe ft;
sy += parent.offsetTo p;
} while ( parent = parent.offsetPa rent );

var sRight=sx+selec tControls[i].offsetWidth-1;
var sBottom=sy+sele ctControls[i].offsetHeight-1;

if (bottom >= sy
&& (x >= sx && x <= sRight
||
right >= sx && right <= sRight))
selectControls[i].style.visibili ty='hidden';
}
else selectControls[i].style.visibili ty='visible';
}
}
Jul 23 '05 #3

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

Similar topics

2
3823
by: Andrea | last post by:
Hi, I'm trying to emulate part of our client-server application as a web site so customers can use it, and I'm stuck when it comes to re-ordering items in a list. Basically we have a list of available articles ("availableItems") and a list of articles already in an issue ("selectedItems"). What I want is to be able to move articles freely between the two lists and then on submission add them to the issue (which I can), but also move...
1
2415
by: Ang Talunin | last post by:
Hey, I wondering if it's possible to retrieve all the <option>-fields from a <select> when posting a <form> to a php file Example: I've got a form like this: <form action = phpfile.php method=post > <select name= "name">
2
30595
by: Manfred | last post by:
Hi I try to change the border of the <select> Tag to a thin, black line. On IE no reaction! <select style="border:1px solid #000000;background-color:red;"> <option>hallo</option> <option>hallo2</option> </select>
6
2408
by: Bonge Boo! | last post by:
This has got to be obvious, but I can't make it work. I have a form called with 3 pull down menus. They are linked to a database which generates the values for the <SELECT? Pull-downs. Lets say I have values selected for all three pull down menus. When I change the first "top-level" menu I want to reset both the second and third menus to the "default" state.
4
2140
by: joiv | last post by:
I'm making a <select></select> with lots of <option></option>. It contains all possible options. Because of the length of the list, I also have an <input type="text">. This is what I wish to do: onKeyDown I want all options that don't contain (or begin with, it doesn't matter which one) the typed letters to be removed from the <select>. My problem is that I don't know of any code to find words and identify
5
8318
by: Brian Foley | last post by:
Hello, I am used to using the label tag with check boxes and radio buttons in html forms. This allows me to click on the text of the label to activate/deactivate the check box / button, rather than having to click on the (possibly small) box or button. I recently tried to assign a label to a select "drop down list", but found that when I clicked on the label text to bring it into focus, the select box was reset to the first entry. ...
6
19614
by: joseph.lindley | last post by:
Forgive me for I am a bit of a web-dev novice - but I'm not doing too bad. I'm currently working with a bit of javascript to dynamically add <option>s into a select box. My code currently works fine in Internet Explorer, however in Firefox the dropdown only displays the first option in the list, and when clicked the other values aren't displayed. Here is the code;
4
39410
by: Man-wai Chang | last post by:
-- iTech Consulting Co., Ltd. Expert of ePOS solutions Website: http://www.itech.com.hk (IE only) Tel: (852)2325 3883 Fax: (852)2325 8288
14
10019
mikek12004
by: mikek12004 | last post by:
In a form I have 5 elements (e.g. pictures) and I wish for the user to be able to set the order of appearance. For this I have for each picture a select box (names select1 to select5) with "please select something" as preselected and the rest options are values from 1 to 5. I want when a user selects a number a.k.a ans <option> that number/<option> to be removed from the rest of the select boxes and when the user selects another number the...
0
8987
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
9366
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
9316
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6793
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
6073
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
4597
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...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2211
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.