javascript - passing variables
I need to pass variables between javascript functions and am having some small problems. Here is an example of what I want to do...
function closeSub(subID){
subID.style.display = 'none';
}
function delayCloseSub(subID){
setTimeout('closeSub(subID)',1000);
}
the error states that subID is undefined. if I call closeSub directly it works.
what am I doing wrong?
Thanks for your help.
Abhishek Reddy posted this at 22:02 — 30th December 2004.
He has: 3,348 posts
Joined: Jul 2001
Try this:
function closeSub(subID){
subID.style.display = 'none';
}
function delayCloseSub(subID){
setTimeout('closeSub(' + subID + ')',1000);
}
?
artsapimp posted this at 01:46 — 31st December 2004.
They have: 330 posts
Joined: Apr 2000
Still generating errors. Here is a replica of what isn't working.
<html>
<head>
<script language='javascript'>
function displaySub(subID){
subID.style.display = '';
}
function closeSub(subID){
alert(subID);
subID.style.display = 'none';
}
function delayCloseSub(subID){
setTimeout('closeSub(' + subID + ')',1000);
}
</script>
</head>
<body>
<div id='testID1' style='display: none'>
test
</div>
<a href='#' onMouseOver='displaySub(testID1)' onMouseOut='delayCloseSub(testID1)'>hover here</a>
</body>
</html>
Thanks for your help
Free Math Test
Fun Math Games
CptAwesome posted this at 10:01 — 31st December 2004.
He has: 370 posts
Joined: Dec 2004
since testID1 is an object, you have to call one of it's values, not the object itself to refer to it, kind of crazy huh? Point is, the following code will work:
function closeSub(subID.id){
subID.style.display = 'none';
}
function delayCloseSub(subID){
setTimeout('closeSub(' +subID.id + ')',1000);
}
(full example)
<html>
<head>
<script language='javascript'>
function displaySub(subID){
subID.style.display = '';
}
function closeSub(subID){
alert(subID.id);
subID.style.display = 'none';
}
function delayCloseSub(subID){
setTimeout('closeSub(' + subID.id + ')',10);
}
</script>
</head>
<body>
<a href='#' onMouseOver='displaySub(testID1)' onMouseOut='delayCloseSub(testID1)'>hover here</a>
<div id='testID1' style='display: none'>
test
</div>
</body>
</html>
artsapimp posted this at 13:26 — 31st December 2004.
They have: 330 posts
Joined: Apr 2000
Thank you very much. You would die laughing if you knew how much code I wrote to get around the .id problem I had.
66 lines of javascript code
7 functions
I think I'll just ad .id back and make it work properly.
Thanks again.
Free Math Test
Fun Math Games
CptAwesome posted this at 18:00 — 31st December 2004.
He has: 370 posts
Joined: Dec 2004
No worries, adding .id was just a guess that I tried that worked, I tried .name first, heh.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.