JS enthusiasts, please help (I'm a struggling novice, so excuse my lack of expertise).
I'm having trouble passing an value from within one function to another, and I don't know why. Perhaps because the values are being passed from within dynamically written HTML. It's really frustrating me.
In the code below, within createMenu function, I'm trying to the pass the imageTagName and imageHoverFileName to the swapImageHover function, as well as the imageTagName and imageReturnFileName to the swapImageReturn function.
Any guidance would be greatly appreciated. Thanks.
-------
<script language="JavaScript">
function createMenu(menuName, menuItems, x, y, w, imageTagName, imageHoverFileName, imageReturnFileName)
{
var divHTML = '<div id="' + menuName + 'MenuDiv" class="DivMenuH" style="left:'+x+'; top:'+y+'; width:'+w+'" onMouseOver="showMenu(' + menuName + 'MenuDiv); swapImageHover(imageTagName, imageHoverFileName)" onMouseOut="hideMenu(' + menuName + 'MenuDiv); swapImageReturn(imageTagName, imageReturnFileName)">';
var tableHTML = '<table border="0" cellspacing="0" cellpadding="0" class="ln_table" id="' + menuName + 'Table">';
var tableRowHTML = "";
var rowCount;
var totalNoRows = menuItems.length;
for (rowCount = 0; rowCount < totalNoRows; rowCount++)
{
tableRowHTML = tableRowHTML + '<tr align="left" valign="middle"><td class="ln_td" style="width:'+w+'"><a href="' + menuItems[rowCount][1] + '"><div id="' + menuName + menuItems[rowCount][0] + '" class="ln_div" style="width:'+w+'" onMouseOver="swapClass(this,\'ln_div_h\')" onMouseOut="swapClass(this,\'ln_div\')">' + menuItems[rowCount][2] + '</div></a></td></tr>';
}
return divHTML + tableHTML + tableRowHTML + '</table></div>';
}
function swapImageHover(imageTagName, imageHoverFileName)
{
document.images[imageTagName].src=imageHoverFileName;
}
function swapImageReturn(imageTagName, imageReturnFileName)
{
document.images[imageTagName].src=imageReturnFileName;
}
function showMenu(menuName)
{
menuName.style.visibility = "visible";
}
function hideMenu(menuName)
{
menuName.style.visibility = "hidden";
}
function swapClass(obj, new_style)
{
obj.className = new_style;
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#ffffff" >
<script language=JavaScript>
document.write(createMenu('Departments', dep, 223, 14, 205,'top_nav','../img/departments_hover.gif','../img/top_nav.gif'))
document.write(createMenu('Employee', emp, 327, 14, 198,'top_nav','../img/employee_news_hover.gif','../img/top_nav.gif'))
document.write(createMenu('Library', lib, 442, 14, 140,'top_nav','../img/library_hover.gif','../img/top_nav.gif'))
document.write(createMenu('Resources', res, 508, 14, 202,'top_nav','../img/resources_hover.gif','../img/top_nav.gif'))
document.write(createMenu('Search', sea, 592, 14, 128,'top_nav','../img/search_hover.gif','../img/top_nav.gif'))
</script>