Click to See Complete Forum and Search --> : Newbie, help me combine commands please


garymm
06-24-2003, 07:21 PM
I am very new to JavaScript, and never had any real teacher, so be patient with me. I am making a menu, which can be viewed (in an earlier form, but still applicable) at the link. the menu (http://homepage.mac.com/garymm/new/) It works as I want it to, but my code is really long. To get every other layer to hide when a new one is made visible, this is the code I use:

onMouseOver="document.luis.src='images/LuisBig.jpg';MM_showHideLayers('Layer1','','show');MM_showHideLayers('Layer2','','hide');MM_showHide Layers('Layer3','','hide');MM_showHideLayers('Layer4','','hide')"

as you can see, I just repeat the hide command over and over again. could you please show me the correct syntax for combining all the layers into one "hide" command? thanks for

Khalid Ali
06-24-2003, 07:44 PM
As it looks like all the layers are named as layer1 ,layer2 and so on...

what you can do is use eval function and create a reference to a layer in a loop,which will create references to all layers you can hide them all at one time

garymm
06-24-2003, 07:49 PM
ok, I understand what you said, but I have no idea how to do it in JavaScript. C++, maybe, but not JavaScript. could you give me a quick example? if it's too much trouble, I will just look it up. my friend has the JavaScript bible, and it should be in there, but I've found real people are the best teachers. thanks.

JHL
06-24-2003, 09:24 PM
this is the code i use:

var arr = new Array('layer1', 'layer2', 'layer3', 'layer4');

function showhide(lid, type)
{
var v = type;

v=(v=='show')?'visible' : (v='hide')?'hidden':v;

for(i=0; i<arr.length; i++)
{
if (arr[i] == lid)
document.getElementById(arr[i]).style.visibility = v;
else
document.getElementById(arr[i]).style.visibility = 'hidden';
}
}

garymm
06-24-2003, 10:02 PM
Thanks. I'm not sure I understand it, but I have something to work with at least. how would I incorporate that into my mouse over stuff?

JHL
06-24-2003, 10:12 PM
onMouseOver="document.luis.src='images/LuisBig.jpg'; showhide('Layer1' ,'show');"