Topic: [HTML/Javascript] DIV does not appear where it should
I am coding the latest versions of my forums, and I am trying to implement pop-up menu's using a simple Javascript code that call's a DIV layer with the menu options already in it, to the link that calls the menu. The javascript is as follows:
<script language="Javascript">
var hideContext=0;
function showMenu(menu,el,position)
{
el = document.getElementById(el);
div = document.getElementById(menu);
//Point of the elements left corner, plus width = right corner
//We want the right edge of the popup to align to the right corner
//So, get the point of the right corner - the width of the menu
//And you get the point of the left corner for the div when alligned
var point = el.offsetLeft + el.offsetWidth;
point = point - div.offsetWidth;
with(document.getElementById(menu))
{
//Move to below item
style.top=el.offsetTop + el.offsetHeight;
//Position depending on align left or right
if(position==1)
style.left=el.offsetLeft;
else if(position==2)
style.left=point;
//Display
style.visibility='visible';
}
clearTimeout(hideContext);
}
function hide(menu)
{
document.getElementById(menu).style.visibility='hidden';
}
</SCRIPT>
The link that calls the menu:
<DIV align="right">Post #1 | <A id="MenuLink1" href="javascript:void(false)" onClick="showMenu('PostMenu1',this.id,2)">Options</A></DIV>
<!-- POPUP MENU -->
<DIV id="PostMenu1" class="Popup">
<A href="PostEdit.asp?ForumID=3&ThreadID=1&PostID=1">Edit</A><BR>
<A href="PostDelete.asp?ForumID=3&ThreadID=1&PostID=1">Delete</A><BR>
<A href="javascript:void(hide('PostMenu1'))">Close</A>
</DIV>
In internet explorer the menu pops-up at the top of the page, not even aligned horizontally as it should. In Firefox, the menu pops-up under the link as it should, but it appears to the left of the page, not aligned with the right side of the link as it should. Any ideas?
Thanks.