Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Popup menu appears behind text input field

Status
Not open for further replies.

idarke

Programmer
Jul 23, 2001
420
US
We have a popup menu at the top of our screen. When the user clicks on it, a menu appears. But if there's a text input field nearby, the popup menu is built behind the input box.

Here is a small html page that demonstrates the problem. I would appreciate any suggestions on how to fix this.


<html>
<body>

<form>
<TABLE width=&quot;100%&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<TR>
<TD align=&quot;left&quot;>
<A HREF=&quot;javascript:showPopup('cpprMenu')&quot;>
Test Menu
</A>
</TD>
</TR>
</TABLE>

Test: <input type=text size=&quot;20&quot; value=&quot;test&quot; name=&quot;mytest&quot;>
</form>



<script>
document.onmousemove = mouseMove
if (document.layers) document.captureEvents(Event.MOUSEMOVE)

var mouseX = 0;
var mouseY = 0;
var clickY = 0;
var astyle = null;
var adiv = null;

var argsArray = null;

function hide()
{
astyle.visibility = &quot;hidden&quot;;
astyle = null;
adiv = null;
}

function showPopup(layer)
{
argsArray = new Array(arguments.length);
for(var i = 1; i < arguments.length; i++)
{
argsArray[i-1] = arguments;
}

var clientHeight;
var offsetHeight;

if(document.layers) // NS <= 4
{
adiv = document.layers[layer];
astyle = adiv;
astyle.bgColor = '#F2F2F8'; // it ignores CSS

clientHeight = self.innerHeight;
offsetHeight = adiv.clip.height;
}
else if(document.all) // IE
{
adiv = document.all(layer);
astyle = adiv.style;

clientHeight = document.body.clientHeight;
offsetHeight = adiv.offsetHeight;
}
else // Gecko: NS >= 6 || Mozilla
{
adiv = document.getElementById(layer);
astyle = adiv.style;

clientHeight = document.body.clientHeight;
offsetHeight = adiv.offsetHeight;
}

if (clientHeight < clickY + offsetHeight)
{
var val = ((mouseY + 3) - offsetHeight);
if(val < 0)
val = 0;
astyle.top = val + (document.layers ? 0 : &quot;px&quot;);
}
else
{
astyle.top = (mouseY - 3) + (document.layers ? 0 : &quot;px&quot;);
}
astyle.left = (mouseX - 3) + (document.layers ? 0 : &quot;px&quot;)
astyle.visibility = &quot;visible&quot;;
}

function mouseMove(e)
{
if (!e) var e = window.event;

if(document.all)
{
mouseX = e.clientX+document.body.scrollLeft;
mouseY = e.clientY+document.body.scrollTop;
clickY = e.clientY;
return; // ie has onmouseleave on the div
}

mouseX = e.pageX;
mouseY = e.pageY;
clickY = (e.clientY ? e.clientY : e.y);

if(astyle == null)
return; // not showing any popup right now

if(astyle.clip)
{
// netscape
var left = astyle.left;
var top = astyle.top;
var right = left+astyle.clip.right;
var bottom = top+astyle.clip.bottom;
}
else
{
// gecko returns the style positions as ###px strings
var left = parseInt(astyle.left);
var top = parseInt(astyle.top);
var right = left+adiv.offsetWidth;
var bottom = top+adiv.offsetHeight;
}

var inlayer = mouseX >= left && mouseX <= right && mouseY >= top && mouseY <= bottom;
if(!inlayer)
{
hide();
}
}
</script>





<STYLE>
DIV.popuplayer
{
position: absolute;
top: 0px;
left: 0px;
z-index: 1;
visibility: hidden;
}
</STYLE>


<div id=&quot;cpprMenu&quot; onmouseleave=&quot;hide()&quot; class=&quot;popuplayer&quot; >
<TABLE border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<TR><TD class=&quot;tdTopTitle1&quot;>&nbsp;</TD></TR>
<TR><TD class=&quot;popup&quot;><A href=&quot;option1&quot;>option1</A></TD></TR>
<TR><TD class=&quot;popup&quot;><A href=&quot;option2&quot;>option2</A></TD></TR>
<TR><TD>&nbsp;</TD></TR>
</TABLE>
</div>


</body>
</html> &quot;When you have eliminated the impossible, whatever remains, however
improbable, must be the truth.&quot; ~ Arthur Conan Doyle
 
if you are trying to make this work with Netscape 4 you will never succeed. NS4 has this problem you see that all form elements will appear in front of everything else.

There is one ugly way to patch the problem though by making all form elements invisible when you have something over it. Not something I would start working on considering the amount of NS4 users still around and the free NS7.

BTW Internet Explorer has the same problem with select boxes. They will appear over anything at all in your page even if the z-index is higher. Only Gecko based browsers work properly regarding that (Netscape 6-7, Mozilla, Phoenix, etc...). Gary Haran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top