Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-11-2004, 07:14 PM   PM User | #1
cdn lover
New to the CF scene

 
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
cdn lover is an unknown quantity at this point
Angry popup menu help

I need help with this popup menu. I type in my javascrpt (using getElementById), test the page and... nothing.

head code:
Quote:
<script>
function showMenu(object) {
if (toClose == 1) {
document.getElementById(oldMenu).style.visibility = "hidden";
}


document.getElementById(obj).style.visibility ="visable";
oldMenu = object;
}

closing(object, standby);

function closing(object, mode) {
if (mode == "standby") {
settimeout("closing(object, close)", 3000);
}
if(mode == "close") {
document.getElementById(object).style.visibility = "hiddin";
if(mode == "wate") {
settimeout("closing(object, wate)", 0000);
}
</script>
<style>
#menu1,#menu2,#menu3,#menu4,#menu5 {
position: absolute;
top: -100px;
left: 100px;
visibility: hidden;
background-color:black;
color:yellow;
</style>
body:
[quote]
...

<table width="20%" bgcolor="yellow">
<tr>
<td>
<a href="#" oncick="showMenu(menu1)">Menu 1</a><br>
<a href="#" onclick="showMenu(menu2)">Menu 2</a><br>
<a href="#" onclick="showMunu(menu3)">Menu 3</a><br>
<a href="#" onclick="showMenu(menu4)">Menu 4</a><br>
<a href="#" onclick="showMenu(menu5)">Menu 5</a><br><br><br>
<img src="http://jigsaw.w3.org/css-validator/images/vcss">


</td>







</table>
</table>

<div id="menu1">
menu 1
</div>
<div id="menu2">
menu2
</div>
<div id="menu3">
menu3
</div>
<div id="menu4">
menu4</div>
<div id="menu5">
menu 5</div>
...[quote]
cdn lover is offline   Reply With Quote
Old 01-11-2004, 07:26 PM   PM User | #2
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
'visable' and 'hidin' should be 'visible' and 'hidden'.
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline   Reply With Quote
Old 01-11-2004, 07:37 PM   PM User | #3
cdn lover
New to the CF scene

 
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
cdn lover is an unknown quantity at this point
My problem still remains
cdn lover is offline   Reply With Quote
Old 01-11-2004, 08:45 PM   PM User | #4
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
Yeah, you have a problem with the setTimeouts and closing calls too. standby should be 'standby', close should be 'close', wate should be 'wate'.

But that isn't enough. You are trying to call the closing function with the local variable object in the timeout, but the timeout is executed in the global scope, not in the local scope, and thus it can't get at the local object variable. You need to eliminate those problems, and the way I would use would be closures, like this:
Code:
function fnCreateClosure( oElement, sMode ){
    return function (){
        closing( oElement, sMode );
    }
}
Using this function, you should change your setTimeouts to look like this example:
Code:
setTimeout( fnCreateClosure(object, 'close'), 3000 );
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

Last edited by liorean; 01-11-2004 at 08:47 PM..
liorean is offline   Reply With Quote
Old 01-12-2004, 12:02 AM   PM User | #5
cdn lover
New to the CF scene

 
Join Date: Jan 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
cdn lover is an unknown quantity at this point
Quote:
Originally posted by liorean
Yeah, you have a problem with the setTimeouts and closing calls too. standby should be 'standby', close should be 'close', wate should be 'wate'.

But that isn't enough. You are trying to call the closing function with the local variable object in the timeout, but the timeout is executed in the global scope, not in the local scope, and thus it can't get at the local object variable. You need to eliminate those problems, and the way I would use would be closures, like this:
Code:
function fnCreateClosure( oElement, sMode ){
    return function (){
        closing( oElement, sMode );
    }
}
Using this function, you should change your setTimeouts to look like this example:
Code:
setTimeout( fnCreateClosure(object, 'close'), 3000 );
And still, the menus won't open.
cdn lover is offline   Reply With Quote
Old 01-12-2004, 02:18 PM   PM User | #6
RadarBob
Regular Coder

 
Join Date: Jun 2002
Location: Round Rock, Texas
Posts: 443
Thanks: 0
Thanked 0 Times in 0 Posts
RadarBob is an unknown quantity at this point
getElementByID() wants a string as an input parameter. It looks like you're sending an object (oldMenu). You need to pass the ID of the desired tag either as a string literal or in a string variable.
RadarBob is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:29 AM.


Advertisement
Log in to turn off these ads.