473,396 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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:absolute" 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="acGeneralMainMenuItem" border="1" rules="none"
cellspacing="0" bordercolor="blue">
<TR class="tableMenuRow">
<TD NOWRAP ONMOUSEOVER="showSubmenu('acGeneralSubmenu',this,' acGeneralMainMenuItem');"
ONMOUSEOUT="hideSubmenu('acGeneralSubmenu');">
&nbsp;General menu&nbsp;<br>
<TABLE id="acGeneralSubmenu"
border="1" rules="none" cellspacing="0" bordercolor="blue"
style="display:none; position:absolute;">
<TR class="tableMenuRow">
<TD NOWRAP id="generalMenuItem0" onclick=
"document.getElementsByTagName('form')[0].actionSelected.value='f158';document.getElementsB yTagName('form')[0].submit()"

ONMOUSEOVER="highlightMenuItem('generalMenuItem0') ;"

ONMOUSEOUT="lowlightMenuItem('generalMenuItem0');" >
&nbsp;General item 1&nbsp;
</TD>
</TR>
<TR class="tableMenuRow">
<TD NOWRAP id="generalMenuItem1"
onclick="document.getElementsByTagName('form')[0].actionSelected.value='f159';document.getElementsB yTagName('form')[0].submit()"
ONMOUSEOVER="highlightMenuItem('generalMenuItem1') ;"
ONMOUSEOUT="lowlightMenuItem('generalMenuItem1');" >
&nbsp;General item 2&nbsp;
</TD>
</TR>
<TR class="tableMenuRow">
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<p>
<input type="hidden" name="actionSelected" 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 lastSubmenuShown='';

// 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="acGeneralMainMenuItem" ...>
// <TR ...>
// <TD NOWRAP ONMOUSEOVER="showSubmenu('acGeneralSubmenu',this,' acGeneralMainMenuItem');"
// ONMOUSEOUT="hideSubMenu('acGeneralSubmenu')">
// General Actions<br>
// <TABLE id="acGeneralSubmenu" style="display:none;
position:absolute;"
// <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(submenuId,parent,mainMenuItemId)
{ // Hide last submenu
if (lastSubmenuShown!='') hideSubmenu(lastSubmenuShown);

// Initialize yOffset with the height of the main menu item minus 2
var yOffset=document.getElementById(mainMenuItemId).of fsetHeight-2;
var x = 0;
var y = yOffset;
do {
x += parent.offsetLeft;
y += parent.offsetTop;
} while ( parent = parent.offsetParent );

var e = document.getElementById( submenuId );
e.style.left = x + 'px';
e.style.top = y + 'px';
e.style.display = '';
var xMax = document.body.scrollLeft + document.body.clientWidth;
if ( x + e.clientWidth > xMax ) {
e.style.left = ( xMax > e.clientWidth ?
( xMax - e.clientWidth ) : 0 ) + 'px';
}

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

lastSubmenuShown=submenuId;

return false;
}

// Define a function to hide the submenu
// Parameters:
// submenuId: the id of the submenu to be hidden
function hideSubmenu(submenuId)
{ document.getElementById(submenuId).style.display = 'none';
return false;
}

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

// Define a function to highlight a menu item
function highlightMenuItem(menuItemId)
{ if (lastHighlightedMenu!='') lowlightMenuItem(lastHighlightedMenu);
document.getElementById(menuItemId).setAttribute(' bgcolor','#aaaaff','false');
lastHighlightedMenu=menuItemId;
}

// Define a function to lowlight a menu item
function lowlightMenuItem(menuItemId)
{ document.getElementById(menuItemId).setAttribute(' bgcolor','white','false')
}
//-->
</script>
</body>
</HTML>
Jul 23 '05 #1
2 6414
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:absolute" 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 "transparent". Changing the style definition from:
style="display:none; position:absolute;
to
style="display:none; position:absolute;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.getElementById(menuItemId).setAttribute(' bgcolor','white','false')
to:
document.getElementById(menuItemId).style.backgrou ndColor = '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.backgroundColor = ...
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*****@agricoreunited.com>
comp.lang.javascript 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.appName 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 showHideSelectControls(action,x,y,width,height)
{ var right=x+width-1;
var bottom=y+height-1;

var selectControls=document.getElementsByTagName("sele ct");
for (var i=0; i<selectControls.length; i++)
{ if (action=='hide')
{ var sx=selectControls[i].offsetLeft;
var sy=selectControls[i].offsetTop;

// sx and sy are relative to parent. Compute absolute values
var parent=selectControls[i].offsetParent;
do {
sx += parent.offsetLeft;
sy += parent.offsetTop;
} while ( parent = parent.offsetParent );

var sRight=sx+selectControls[i].offsetWidth-1;
var sBottom=sy+selectControls[i].offsetHeight-1;

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

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

Similar topics

2
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...
1
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...
2
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>...
6
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...
4
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:...
5
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...
6
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...
4
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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...

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.