Page 1 of 1

how to pass a variable in javascript?

Posted: Sun Jul 28, 2002 10:49 am
by kaily
I think javascript is a bit same as PHP, so I write the code:

Code: Select all

<html>
<head>
<script language=JavaScript1.2>
function Show(divid) &#123;
	divid.filters.revealTrans.apply();
	divid.style.visibility = "visible";
	divid.filters.revealTrans.play();
&#125;
function Hide(divid) &#123;
	divid.filters.revealTrans.apply();
	divid.style.visibility = "hidden";
	divid.filters.revealTrans.play();
&#125;
function menudown(target)&#123;
setTimeout("Hide(target)",5000);
&#125;
</script>
</head>
<body>
<!-- HERE, the link "HELP" -->

<a href="help.php" onMouseOver="Hide(lastdiv); document.lastdiv=help; Show(lastdiv);" onmouseout="menudown(help)">HELP!</a>

   <div id="space" class=menu style="width: 0; height: 0; left: 0; top: 0"> </div>
   <div id="help" class=menu style="left:658px; width: 75px;; top: 25px"> 
	<table bgcolor=#000000 cellspacing=0 cellpadding=1>
	 <tr> 
	  <td> 
	   <table width=100% cellspacing=0 cellpadding=4 bgcolor=#dddddd>
		<tr> 
		 <td align="center"> <a href=abc.php>abc</a></td>
		</tr>
		<tr> 
		 <td align="center"><a href=faq.php>faq</a></td>
		</tr>
		<tr> 
		 <td align="center"><a href=about.php>about</a></td>
		</tr>
	   </table>
	  </td>
	 </tr>
	</table>
   </div>
  <script language=JavaScript1.2>
document.lastdiv=space;
</script>
</body></html>
:arrow: when my mouse over the link, the menu show up,but when my mouse out, the menu doesn't show down the menudown function doesn't work!
WHY? :?: :?:
Any idea?
Sorry for my english.

Posted: Sun Jul 28, 2002 2:20 pm
by gnu2php
I don't think it'll work unless you pass a "global" variable to Hide(), since timeout functions seem to require it.

Try this. It sets a global variable "curr_target" to "target":

Code: Select all

function menudown(target)&#123; 
curr_target=target;
setTimeout("Hide(curr_target)",5000); 
&#125;
The only problem is that if you call menudown() again before Hide() is actually called, the curr_target variable is altered.

You might try something like this:

Code: Select all

var timer = 0;

function menudown(target)&#123;
if (timer) clearTimeout(timer);
curr_target=target;
timer = setTimeout("Hide(curr_target)",5000);
&#125;

Posted: Mon Jul 29, 2002 8:25 am
by volka
for DOM2 there is an window.event object holding the event informations.
window.event.src contains a reference to the -uhm, well- source ;)
You may use this to avoid the global var.