/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Mini Rotating Menu

I have created a very simple menu index.
It works OK with one reference, but not perfect with two.

My attempt was to create two rotating menus. See “More” and “Travel” Links
embedded between the ‘Main Menu #’ displays.
Each time you click on the “More”, for example, a small sub-menu of links
displays that changes (rotates through the total count).

When I alternately click on the “More” and “Travel” links, one or the other seems
to get confused and displays more than one of the rotation selections.

I suspect it has something to do with the “ToggleParamCount’.
I thought I was being smart by having it in part of the JSON definition
but now I’m just confused as to what is happening.
Is there some sort of interaction I’m not accounting for when I create
the references

[code]
var MoreStuff = DisplayToggles;
var TravelStuff = DisplayToggles;
[/code]

Any suggestions?

[code=php]
<html>
<head>
<title>Mini Menu</title>

<style type=”text/css”>
td {
font:11px Verdana, Arial, Helvetica, sans-serif;
color:#003366;
width:200px;
}
.NavMenu { display:none; }
</style>

<script type=”text/javascript”>
stateOn = ‘block’; stateOff = ‘none’;

function ToggleDisplay(ids) {
var CState = document.getElementById(ids);
if ((CState.style.display == stateOff) || (CState.style.display == ”))
{ CState.style.display = stateOn; } else { CState.style.display = stateOff; }
}

var DisplayToggles = {
ToggleParamsCnt : 0,
ToggleParams : function() {
var argv = arguments; // collect parameters in array
var argc = argv.length; // save length of array
var Info = argv[this.ToggleParamsCnt]; // get information for current parameter
var CState = document.getElementById(Info);
if ((CState.style.display == stateOff) || (CState.style.display == ”)) {
CState.style.display = stateOn; // display
} else {
CState.style.display = stateOff; // remove display
this.ToggleParamsCnt = (this.ToggleParamsCnt+1) % argc; // get next parameter in list (modulo max array size)
Info = argv[this.ToggleParamsCnt];
CState = document.getElementById(Info);
if ((CState.style.display == stateOff) || (CState.style.display == ”))
{ CState.style.display = stateOn; } else { CState.style.display = stateOff; }
}
},
ToggleParamsOff : function() {
var argv = arguments; // collect parameters in array
for (var i=0; i<argv.length; i++) { document.getElementById(argv[i]).style.display = stateOff; }
}
}
var MoreStuff = DisplayToggles;
var TravelStuff = DisplayToggles;
</script>

</head>
<body>

<table border=”0″>
<tr> <td>

<a href=”javascript:void(0)” onClick=”ToggleDisplay(‘Menu1’)”>Main Menu 1</a>
<div id=”Menu1″ class=”NavMenu”>
<br />Sub-Menu 1-1
<br />Sub-Menu 1-2
<br />Sub-Menu 1-3
</div>
</td> </tr>

<tr> <td>

<div style=”padding-left:0.5cm”>
<a href=”javascript:void(0)” onClick=”MoreStuff.ToggleParams(‘CV’,’Labs’,’Proj’,’Misc’)”>More</a>
<a href=”javascript:void(0)” onClick=”MoreStuff.ToggleParamsOff(‘CV’,’Labs’,’Proj’,’Misc’)”>Links</a>

<div id=”CV” style=”display:none”>
<br />Curriculum Vitae
<br /><a href=”javascript:void(0)”>Brief</a> &amp;
<a href=”javascript:void(0)”>Extended</a>
<p />Portfolios
<br /><a href=”javascript:void(0)”>Teaching</a> &amp;

<br /><a href=”javascript:void(0)”>Administrative</a> &amp;
<br /><a href=”javascript:void(0)”>Creation</a>
</div>
<div id=”Labs” style=”display:none”>
<br />Labs
<br /><a href=”javascript:void(0)”>Lab 1</a>
<a href=”javascript:void(0)”>Lab 2</a>
<br /><a href=”javascript:void(0)”>Lab 3</a>

<a href=”javascript:void(0)”>Lab 4</a> &amp;
<a href=”javascript:void(0)”>Lab 5</a>
<p />Classes
<br /><a href=”javascript:void(0)”>Class 1</a>
<a href=”javascript:void(0)”>Class 2</a>
<a href=”javascript:void(0)”>Class 3</a>
</div>
<div id=”Proj” style=”display:none”>

<br />Projects
<br /><a href=”javascript:void(0)”>1</a>
<a href=”javascript:void(0)”>2</a>
<a href=”javascript:void(0)”>3</a>
<a href=”javascript:void(0)”>4</a>
<a href=”javascript:void(0)”>5</a>
<p />Simulations
<p />Reference Links

</div>
<div id=”Misc” style=”display:none”>
<br />Web Boards
<p />Surveys
</div>

</div>
</td> </tr>

<tr> <td>
<a href=”javascript:void(0)” onClick=”ToggleDisplay(‘Menu2’)”>Main Menu 2</a>

<div id=”Menu2″ class=”NavMenu”>
<br />Sub-Menu 2-1
<br />Sub-Menu 2-2
<br />Sub-Menu 2-3
</div>
</td> </tr>

<tr><td>
<div style=”padding-left:0.5cm”>
<a href=”javascript:void(0)” onClick=”TravelStuff.ToggleParams(‘Cars’,’Trains’,’Planes’,’Trucks’,’Boats’)”>Travel</a>
<a href=”javascript:void(0)” onClick=”TravelStuff.ToggleParamsOff(‘Cars’,’Trains’,’Planes’,’Trucks’,’Boats’)”>Links</a>

<div id=”Cars” style=”display:none”>
<br />GM
<p />Ford
<p />Chrysler
<p />Honda
<p />Toyota
</div>
<div id=”Trains” style=”display:none”>
<br />Steam
<br />Electric
<br />Diesel
</div>
<div id=”Planes” style=”display:none”>
<br />Model
<br />Private
<br />Commercial
<br />Military

</div>
<div id=”Trucks” style=”display:none”>
<br />Small
<br />Medium
<br />Large
</div>
<div id=”Boats” style=”display:none”>
<br />Row
<br />Sail
<br />Speed
<br />Yacht
<br />Cruiser
<br />Pleasure
</div>

</div>
</td></tr>

<tr> <td>
<a href=”javascript:void(0)” onClick=”ToggleDisplay(‘Menu3’)”>Main Menu 3</a>
<div id=”Menu3″ class=”NavMenu”>
<br />Sub-Menu 3-1
<br />Sub-Menu 3-2
<br />Sub-Menu 3-3
</div>

</td> </tr>

</table>

</body>
</html>
[/code]

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERauthorSep 02.2007 — I'm still trying to determine what's wrong with the code.

In an attempt to find out, I put an alert message in like this.
<i>
</i> ToggleParams : function() {
alert(this.ToggleParamsCnt);
....


Now when I click on the 'More' and 'Travel' links, I get the value of the last display section. It looks like I don't have two different objects as I had expected to increment the ToggleParamsCnt. The one variable appears to be being shared between the two object definitions.

Any ideas on how to change the 'MoreStuff' and 'TravelStuff' definitions so that the reference to this.ToggleParamsCnt increments the correct object variable?
Copy linkTweet thisAlerts:
@Arty_EffemSep 03.2007 — 
Is there some sort of interaction I'm not accounting for when I create

the references
<i>
</i>var MoreStuff = DisplayToggles;
var TravelStuff = DisplayToggles;

[/QUOTE]
Yes. [I]DisplayToggles[/I] is a static object, so both those references point to the same object, so calling a method for either, acts upon the same data.

If you continue to use a static object, one of its properties needs to be an array of objects, each of which stores the data for a different menu.
Copy linkTweet thisAlerts:
@JMRKERauthorSep 03.2007 — @Arty_Effem,

Thanks for the info.

What I thought I was doing was not calling a 'static object', but an object that could be called multiple times. What you say is exactily how it is acting because with the right combination of clicks I can get an undefined reference as there are different parameter counts being looked for.

Do you, or anyone, have a suggestion to change the call or definition so that I can use the object multiple times without knowing ahead of time how many objects I would need as in the array definition modification?
Copy linkTweet thisAlerts:
@vwphillipsSep 03.2007 — [CODE]<html>
<head>
<title>Mini Menu</title>

<style type="text/css">
td {
font:11px Verdana, Arial, Helvetica, sans-serif;
color:#003366;
width:200px;
}
.NavMenu { display:none; }
</style>

<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

function zxcRotateMenu(){
var zxcargs=zxcRotateMenu.arguments;
var zxcobj=(typeof(zxcargs[0])=='object')?zxcargs[0]:document.getElementById(zxcargs[0]);
if (!zxcobj.ary){
zxcobj.cnt=0;
zxcobj.ary=[];
for (var zxc0=1;zxc0<zxcargs.length;zxc0++){
zxcobj.ary.push(document.getElementById(zxcargs[zxc0]));
}
}
if (zxcobj.last) zxcobj.last.style.display='none';
if (zxcargs.length>1){
zxcobj.last=zxcobj.ary[zxcobj.cnt];
zxcobj.last.style.display='';
zxcobj.cnt=++zxcobj.cnt%zxcobj.ary.length;
}
}

/*]]>*/
</script>
</head>
<body>

<table border="0">
<tr> <td>

<a href="javascript:void(0)" onClick="ToggleDisplay('Menu1')">Main Menu 1</a>
<div id="Menu1" class="NavMenu">
<br />Sub-Menu 1-1
<br />Sub-Menu 1-2
<br />Sub-Menu 1-3
</div>
</td> </tr>

<tr> <td>

<div style="padding-left:0.5cm">
<a id="a1" href="javascript:void(0)" onClick="zxcRotateMenu(this,'CV','Labs','Proj','Misc')">More</a>
<a href="javascript:void(0)" onClick="zxcRotateMenu('a1')">LINKS</a>

<div id="CV" style="display:none">
<br />Curriculum Vitae
<br /><a href="javascript:void(0)">Brief</a> &amp;
<a href="javascript:void(0)">Extended</a>
<p />Portfolios
<br /><a href="javascript:void(0)">Teaching</a> &amp;

<br /><a href="javascript:void(0)">Administrative</a> &amp;
<br /><a href="javascript:void(0)">Creation</a>
</div>
<div id="Labs" style="display:none">
<br />Labs
<br /><a href="javascript:void(0)">Lab 1</a>
<a href="javascript:void(0)">Lab 2</a>
<br /><a href="javascript:void(0)">Lab 3</a>

<a href="javascript:void(0)">Lab 4</a> &amp;
<a href="javascript:void(0)">Lab 5</a>
<p />Classes
<br /><a href="javascript:void(0)">Class 1</a>
<a href="javascript:void(0)">Class 2</a>
<a href="javascript:void(0)">Class 3</a>
</div>
<div id="Proj" style="display:none">

<br />Projects
<br /><a href="javascript:void(0)">1</a>
<a href="javascript:void(0)">2</a>
<a href="javascript:void(0)">3</a>
<a href="javascript:void(0)">4</a>
<a href="javascript:void(0)">5</a>
<p />Simulations
<p />Reference Links

</div>
<div id="Misc" style="display:none">
<br />Web Boards
<p />Surveys
</div>

</div>
</td> </tr>

<tr> <td>
<a href="javascript:void(0)" onClick="ToggleDisplay('Menu2')">Main Menu 2</a>

<div id="Menu2" class="NavMenu">
<br />Sub-Menu 2-1
<br />Sub-Menu 2-2
<br />Sub-Menu 2-3
</div>
</td> </tr>

<tr><td>
<div style="padding-left:0.5cm">
<a id="a2" href="javascript:void(0)" onClick="zxcRotateMenu(this,'Cars','Trains','Planes','Trucks','Boats')">Travel</a>
<a href="javascript:void(0)" onClick="zxcRotateMenu('a2')">Links</a>

<div id="Cars" style="display:none">
<br />GM
<p />Ford
<p />Chrysler
<p />Honda
<p />Toyota
</div>
<div id="Trains" style="display:none">
<br />Steam
<br />Electric
<br />Diesel
</div>
<div id="Planes" style="display:none">
<br />Model
<br />Private
<br />Commercial
<br />Military

</div>
<div id="Trucks" style="display:none">
<br />Small
<br />Medium
<br />Large
</div>
<div id="Boats" style="display:none">
<br />Row
<br />Sail
<br />Speed
<br />Yacht
<br />Cruiser
<br />Pleasure
</div>

</div>
</td></tr>

<tr> <td>
<a href="javascript:void(0)" onClick="ToggleDisplay('Menu3')">Main Menu 3</a>
<div id="Menu3" class="NavMenu">
<br />Sub-Menu 3-1
<br />Sub-Menu 3-2
<br />Sub-Menu 3-3
</div>

</td> </tr>

</table>

</body>
</html>[/CODE]
Copy linkTweet thisAlerts:
@JMRKERauthorSep 03.2007 — Thank you 'Vic'.


That is a solution that works as I wanted but that I would never have thought of for a very long time.

In an attempt to understand what you did, I have put my comments of (mis-)understanding of your code.


Most of the lines with ??? have some point that I would like further clarification if you have the time to look at it.


I'm not sure I'm using the correct nomenclature, so feel free to correct my comments.

I'm not sure what the

/*<![CDATA[*/

...

/*]]>*/

surrounding the code is about, but I assume it is required either for IE or XML usage.

Continuing on with commented code...
[code=php]
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

function zxcRotateMenu(){

var zxcargs=zxcRotateMenu.arguments; // get array of parameter passed to function
// function passed either
// 1. ID of link (object)
// 2. this (???) and array of IDs (not objects???) to display

var zxcobj=(typeof(zxcargs[0])=='object')?zxcargs[0]:document.getElementById(zxcargs[0]);
// looks at 1st parameter passed to function
// 1. if ID is object, set zxcobj variable to ID
// 2. if this (???) is array, the check to see if list already created

if (!zxcobj.ary){ // if .ary exists, bypass creation
zxcobj.cnt=0; // initialize rxcobj.cnt to zero
zxcobj.ary=[]; // initialize rxcobj.ary to null
for (var zxc0=1; zxc0<zxcargs.length; zxc0++){ // create zxcobj.ary array elements from arguments passed
zxcobj.ary.push(document.getElementById(zxcargs[zxc0]));
} // note that 1st element skipped over (does not not start zxc0=0)
}

if (zxcobj.last) zxcobj.last.style.display='none'; // reset display of last object displayed
// ??? zxcobj.last was initialized by the zxcobj.ary creation above to length of arguments passed

if (zxcargs.length>1){ // check to see if arguments were passed
zxcobj.last=zxcobj.ary[zxcobj.cnt]; // get argument at cnt position in argument array
zxcobj.last.style.display=''; // set display so that it is not 'none'
zxcobj.cnt=++zxcobj.cnt%zxcobj.ary.length; // increment to next argument count
// ??? unsure of this command.
// maybe??? zxcobj.cnt =+ +zxcobj.cnt % zxcobj.ary.length;

// meaning set cnt equal to ((next cnt) modulo (size of array)) ???
}
}

/*]]>*/
</script>
[/code]


Either way, thank you for the code. ?
Copy linkTweet thisAlerts:
@vwphillipsSep 04.2007 — [CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

function zxcRotateMenu(){

var zxcargs=zxcRotateMenu.arguments; // get array of parameter passed to function
// function passed either
// 1. ID of link (object) // for hiding zxcobj.last, the ID is of the link object
// 2. this (the link object)(could also use the ID of the link object) and array of IDs (not objects???) to display

var zxcobj=(typeof(zxcargs[0])=='object')?zxcargs[0]:document.getElementById(zxcargs[0]);
// looks at 1st parameter passed to function
// 1. if ID is object, set zxcobj variable to ID if args[0] is an object, use it, If args[0] is a string convert to an object using getElementById
// 2. if this (???) is array, the check to see if list already created
// no args[0] must be the link object or link ID

if (!zxcobj.ary){ // if .ary exists, bypass creation
zxcobj.cnt=0; // initialize rxcobj.cnt to zero
zxcobj.ary=[]; // initialize rxcobj.ary to null
for (var zxc0=1; zxc0<zxcargs.length; zxc0++){ // create zxcobj.ary array elements from arguments passed ** yest the sub menu objects
zxcobj.ary.push(document.getElementById(zxcargs[zxc0]));
} // note that 1st element skipped over (does not not start zxc0=0) because 0 is the link object
}

if (zxcobj.last) zxcobj.last.style.display='none'; // reset display of last object displayed
// ??? zxcobj.last was initialized by the zxcobj.ary creation above to length of arguments passed
// No it is created 2 lines below when the function is first called
if (zxcargs.length>1){ // check to see if arguments were passed
zxcobj.last=zxcobj.ary[zxcobj.cnt]; // get argument at cnt position in argument array
zxcobj.last.style.display=''; // set display so that it is not 'none'
zxcobj.cnt=++zxcobj.cnt%zxcobj.ary.length; // increment to next argument count
// ??? unsure of this command.
// Tis just a clever way of cycling the count back to 0 when at zxcobj.ary.length
// increment zxcobj.cnt and make the count the modlus of zxcobj.ary.length
// maybe??? zxcobj.cnt =+ +zxcobj.cnt % zxcobj.ary.length;
// meaning set cnt equal to ((next cnt) modulo (size of array)) ???
}
}

/*]]>*/
</script> </head>

<body>

</body>

</html>[/CODE]


My editor 'Webbuilder 2006' considers

[CODE]
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

/*]]>*/
</script>
[/CODE]


correct for

[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

[/CODE]


Change as you feel fit as I don't know what doctype you are going to use
Copy linkTweet thisAlerts:
@JMRKERauthorSep 04.2007 — To All and especially Vic ... Thank you very much.
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...