|
-
Jun 17th, 2003, 09:18 AM
#1
Thread Starter
Hyperactive Member
problem passing parameters to function that is a parameter itself in setTimeout()
Hello
I am having a small problem which I thought I resolved a while back...unfortunately it's back
it's a dropdown layer that waits 1 second before closing.
here is my code
Code:
<script>
var delay;
function swap()
{
var nameOfLayer = swap.arguments[0];
if(window.delay)
{
clearTimeout(delay);
}
if(swap.arguments[1] == 1)
{
document.getElementById(nameOfLayer).style.visibility = "visible";
}
else
{
document.getElementById(nameOfLayer).style.visibility = "hidden";
}
}
function wait()
{
var n = wait.arguments[0];
delay = setTimeout("swap(' + n + ',2)",1000);
// if i change ' + n + ' to the name of layer it works fine
// delay = setTimeout("swap('lay1',2)",1000);
}
</script>
here is how I call the function
Code:
<p><a href = "" onMouseover="swap('lay1',1)" onMouseout="wait('lay1')" >Wawryn Classroom</a></p>
i always have problems passing parameters to a function that is itself a parameter of the setTimeout function
any help will be appreciated
bsw
-
Jun 17th, 2003, 06:13 PM
#2
Fanatic Member
You've almost got it. In your wait function change the ' + n + ' to '" + n + "'.
Basically the string is not being compiled correctly. Here's what the function would look like.
Code:
function wait()
{
var n = wait.arguments[0];
delay = setTimeout("swap('" + n + "',2)",1000);
}
I'd also recommend placing your arguments as named parameters of the function. It is easier to read and can save some coding.
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
Jun 17th, 2003, 11:58 PM
#3
Thread Starter
Hyperactive Member
right on 
this will work
ya i normaly put the params in, but i was being lazy
thanks for the tips
bsw
-
Jun 18th, 2003, 06:47 AM
#4
You chose a more difficult, longer to write and more complicated approach because you were LAZY?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jun 18th, 2003, 08:29 AM
#5
Thread Starter
Hyperactive Member
yes
if I wouldn't be lazy I would read more javascript tutorials and wouldn't be getting stuck every two seconds 
what is the correct approach CornedBee?
how can I make it more efficient and generic
bsw
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|