Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 21st, 2004, 08:16 PM
Authorized User
 
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing a value from one function to another

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>

 
Old March 22nd, 2004, 04:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think it is because all your double and single quote signs are mixed up! There is quite a lot of information about this on this forum and on the net in general!

Sorry, I cannot remember how it goes in JavaScript, but I have always used double quotes as the outermost quote signs, and escaped all other quotes inside strings.

Hope it helps!

Jacob.

 
Old March 22nd, 2004, 04:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have made this small page for you...
Code:
<HTML>
<HEAD>
<SCRIPT>
function testFunction()
{
    var tmp = "test function";
    alert("this is a so-called '" + tmp + "', and " + 
    "if you want to use a \" you should " + 
    "use backslashes as \\\" to escape the double " + 
    "quote sign.");
}
</SCRIPT>
</HEAD>
<BODY onload="testFunction();"></BODY>
</HTML>
It will show you about the single and double quote signs!

Jacob.

 
Old March 22nd, 2004, 07:45 PM
Authorized User
 
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you, Jacob.

This was helpful. I was able to work this out applying your advice.

Bradley (alias "PortGuy")

 
Old October 17th, 2005, 06:01 AM
Registered User
 
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to neeraj_gill1 Send a message via Yahoo to neeraj_gill1
Default

Quote:
quote:Originally posted by PortGuy
 Thank you, Jacob.

This was helpful. I was able to work this out applying your advice.

Bradley (alias "PortGuy")






Similar Threads
Thread Thread Starter Forum Replies Last Post
passing references to a function demac43 Excel VBA 4 November 15th, 2006 04:23 PM
Passing an array to a Sub or Function donrafeal Access VBA 2 May 11th, 2006 09:39 AM
Passing Parameters to a function atcs2152 Ajax 4 December 22nd, 2005 09:12 AM
passing variable to function Boszky Pro PHP 2 December 15th, 2005 03:01 AM
passing datatype as a function argument texasraven VB.NET 0 September 23rd, 2003 10:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.