doccee2006
Programmer
I'm creating a very simple popup menu for a client's page. The menus are written into an existing <div> and the positioning and visibility are switched with the js functions. The menus are being created correctly, but the hrefs won't work directly, although I've used a document.write to verify and validate the code within the menu, and right-clicking on a link and selecting open link will work. Also, the MouseOver on the menu will keep it in place, but the MouseOut doesn't hide it. MouseOver and MouseOut work correctly on the other areas of the page. I don't know if this is a z-index problem, or a DOM issue. Any help will be appreciated. Here's the info:
Test page is online at:
(only 2 menus are active right now, head and neck and they work from the illustration or the sidebar.)
Here's the js file:
var onImg;
var imgID, pic;
var toppos, leftpos, active, offpic;
var menu_content='';
function goTo(loc){
document.location="loc";
}
function show(toppos,leftpos,active,imgID,pic,offpic){
var active_menu=eval('menu'+active);
var active_labels=eval('labels'+active);
menu=(active_menu.split(","));
labels=(active_labels.split(","));
menu_content="<div onMouseOver=\"show('"+toppos+"','"+leftpos+"','"+active+"','"+imgID+"','"+pic+"');\" onMouseOut=\"hide('"+imgID+"','"+offpic+"');\">";
menu_content+='<table cellpadding=0 cellspacing=0 border=0 style="border-collapse:collapse;" class="menu">';
for (i in menu){
menu_content+='<tr><td class="choice">';
menu_content+='<a href="'+menu+'" onClick="goTo(\''+labels+'\');" class="choice">'+labels+'</a><br>';
menu_content+='</td></tr>';
}
menu_content+='</table></a>';
// document.write(menu_content);
document.getElementById('a_menu').style.top=toppos+'px';
document.getElementById('a_menu').style.left=leftpos+'px';
document.getElementById('a_menu').innerHTML=menu_content;
document.getElementById('a_menu').style.visibility='visible';
document.getElementById(imgID).src='assets/'+pic;
menu_content = '';
}
function hide(imgID,pic){
document.getElementById('a_menu').style.visibility='hidden';
document.getElementById(imgID).src='assets/'+pic;
}
The strings for the menu content are sent in a separate js file so the client can edit easily:
<!--
menu1='mouth.htm,nose.htm,ear.htm';
labels1='MOUTH,NOSE,EAR';
menu2='cervical_spine.htm,throat.htm';
labels2='SPINE,THROAT';
//-->
Here's the stylesheet for the menus:
.menu {
font-family:Arial,Helvetica,sans-serif;
font-size:11px;
background-color:#555555;
border-left:#777777 1px solid;
border-top:#777777 1px solid;
border-right:#777777 1px solid;
border-bottom:#777777 1px solid;
text-align:center;
padding:0;
width:100;
line-height:13px;
}
.choice {
width:100%;
border-bottom:#777777 1px solid;
border-right:#777777 1px solid
}
a {
font-family:Arial,Helvetica,sans-serif;
color:#0000FF;
background-color:#FFFFFF;
text-decoration:none
}
a:visited {
font-family:Arial,Helvetica,sans-serif;
color:#0000FF;
background-color:#FFFFFF
}
a:hover {
font-family:Arial,Helvetica,sans-serif;
color:#FF0000;
background-color:#FFFFFF
}
#a_menu {
visibility:hidden;
position:absolute;
background-color:#FFF;
}
Hopefully that will be enough information. Thanks in advance!
Doc
Test page is online at:
(only 2 menus are active right now, head and neck and they work from the illustration or the sidebar.)
Here's the js file:
var onImg;
var imgID, pic;
var toppos, leftpos, active, offpic;
var menu_content='';
function goTo(loc){
document.location="loc";
}
function show(toppos,leftpos,active,imgID,pic,offpic){
var active_menu=eval('menu'+active);
var active_labels=eval('labels'+active);
menu=(active_menu.split(","));
labels=(active_labels.split(","));
menu_content="<div onMouseOver=\"show('"+toppos+"','"+leftpos+"','"+active+"','"+imgID+"','"+pic+"');\" onMouseOut=\"hide('"+imgID+"','"+offpic+"');\">";
menu_content+='<table cellpadding=0 cellspacing=0 border=0 style="border-collapse:collapse;" class="menu">';
for (i in menu){
menu_content+='<tr><td class="choice">';
menu_content+='<a href="'+menu+'" onClick="goTo(\''+labels+'\');" class="choice">'+labels+'</a><br>';
menu_content+='</td></tr>';
}
menu_content+='</table></a>';
// document.write(menu_content);
document.getElementById('a_menu').style.top=toppos+'px';
document.getElementById('a_menu').style.left=leftpos+'px';
document.getElementById('a_menu').innerHTML=menu_content;
document.getElementById('a_menu').style.visibility='visible';
document.getElementById(imgID).src='assets/'+pic;
menu_content = '';
}
function hide(imgID,pic){
document.getElementById('a_menu').style.visibility='hidden';
document.getElementById(imgID).src='assets/'+pic;
}
The strings for the menu content are sent in a separate js file so the client can edit easily:
<!--
menu1='mouth.htm,nose.htm,ear.htm';
labels1='MOUTH,NOSE,EAR';
menu2='cervical_spine.htm,throat.htm';
labels2='SPINE,THROAT';
//-->
Here's the stylesheet for the menus:
.menu {
font-family:Arial,Helvetica,sans-serif;
font-size:11px;
background-color:#555555;
border-left:#777777 1px solid;
border-top:#777777 1px solid;
border-right:#777777 1px solid;
border-bottom:#777777 1px solid;
text-align:center;
padding:0;
width:100;
line-height:13px;
}
.choice {
width:100%;
border-bottom:#777777 1px solid;
border-right:#777777 1px solid
}
a {
font-family:Arial,Helvetica,sans-serif;
color:#0000FF;
background-color:#FFFFFF;
text-decoration:none
}
a:visited {
font-family:Arial,Helvetica,sans-serif;
color:#0000FF;
background-color:#FFFFFF
}
a:hover {
font-family:Arial,Helvetica,sans-serif;
color:#FF0000;
background-color:#FFFFFF
}
#a_menu {
visibility:hidden;
position:absolute;
background-color:#FFF;
}
Hopefully that will be enough information. Thanks in advance!
Doc