How to do a For x=1 to 10 kinda loop

P

Paul Bruneau

Hi Everybody,

I've adapted a tutorial to make my own navigation menu.
Its an "Expanding/Contracting" kind of menu that looks
neat and simple and a toggle to "Expand/Contract" any
of the menu-chains works fine...
Problem is... I need to control "when" any of the menus
is in an "Expand/Contract" mode. Otherwise, a menu script
isn't worth diddly.

I thought... Contract them all, and then just Expand the
single one I want to.

This would be the pseudo-script. Will someone help me
javascript it? I really don't understand javascripts For logic.

I've named the ID for each menu-chain "m1", "m2", "m3"
so that I could do this loop


Function MainMenu(list)
{
FOR x = 1 to 15
document.getElementById('m'+x).style.display='none'; // Closes the menu-chain
Next x
document.getElementById(list).style.display='block'; // Opens the menu-chain by name
}


Many thanks

Paul
 
M

mscir

Paul said:
Hi Everybody,

I've adapted a tutorial to make my own navigation menu.
Its an "Expanding/Contracting" kind of menu that looks
neat and simple and a toggle to "Expand/Contract" any
of the menu-chains works fine...
Problem is... I need to control "when" any of the menus
is in an "Expand/Contract" mode. Otherwise, a menu script
isn't worth diddly.

I thought... Contract them all, and then just Expand the
single one I want to.

This would be the pseudo-script. Will someone help me
javascript it? I really don't understand javascripts For logic.

I've named the ID for each menu-chain "m1", "m2", "m3"
so that I could do this loop
Function MainMenu(list) {
FOR x = 1 to 15
document.getElementById('m'+x).style.display='none'; // Closes the menu-chain
Next x
document.getElementById(list).style.display='block'; // Opens the menu-chain by name
}


Many thanks
Paul

http://www.w3schools.com/js/js_looping.asp

for

The for statement will execute a block of code a specified number of times

for (initialization; condition; increment)
{
code to be executed
}

for (var x=1; x<16; x++){
document.getElementById('m'+x).style.display='none';
}

Mike
 
P

Paul Bruneau

Thanks Mike,

That snippet was a cool way to express the step.

Thank you for the help

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,607
Members
45,241
Latest member
Lisa1997

Latest Threads

Top