Forum Moderators: open
Here's an idea that may or may not be appropriate for your situation. If you want to pass multiple pieces of true/false information in one argument, you could do it with a binary string. For example, you could make your function interpret "10010" as true, false, false, true, false.
function displaylayer(x,y,z) {
if (x==1) {
document.getElementById("layer1").style.display="block" }
else {
document.getElementById("layer1").style.display="none" }
if (y==1) {
document.getElementById("layer2").style.display="block" }
else {
document.getElementById("layer2").style.display="none" }
if (z==1) {
document.getElementById("layer3").style.display="block" }
else {
document.getElementById("layer3").style.display="none" }
}
Then I have a reference in the body like this :
<a href="#" onclick="displaylayer(1,0,0); return false"><img src="image1.jpg"></a>
<div id="layer1" style="display:none">
<a href="#" onclick="displaylayer(0,1,0); return false"><img src="image1.jpg"></a>
<div id="layer2" style="display:none">
<a href="#" onclick="displaylayer(0,0,1); return false"><img src="image1.jpg"></a>
<div id="layer3" style="display:none">
I can get it to work this way no problem; but I would like to be able to make it so that I can send one of the three values :
<a href="#" onclick="displaylayer(1,,); return false">...
So that it won't change the other two values. Does that make sense? The reason I'd like to do it is so that I can display one layer at a time, or two layers, or all three layers, or any combination of the two layers. The way I have it now I can only display one layer at a time. Hope this helps instead of confuses.
function switchOn(layer) {
document.getElementById(layer).style.display="block";
}
function switchOff(layer) {
document.getElementById(layer).style.display="none";
}
function switchOnAll() {
switchOn("layer1");
switchOn("layer2");
...etc...
}
... onclick="switchOn('layer1');" onmouseout...
<a href="#" onclick="displaylayer("layer1",1); return false"><img src="image1.jpg"></a>
Instead of :
<a href="#" onclick="displaylayer('layer1',1); return false"><img src="image1.jpg"></a>
So thank you very much again for the input.
[edited by: rahmuss at 9:21 pm (utc) on Jan. 6, 2004]
function displayOneLayer(layerNum)
{
var maxLayer = 3;
for (var i=1; i<=maxLayer; i++)
{
var layerName = 'layer' + i;
var theLayer = document.getElementById(layerName);
if (i == layerNum)
{
theLayer.style.display = "block";
}
else
{
theLayer.style.display = "none";
}
}
}
<a href="#" onclick="displayOneLayer(1); return false;"><img src="image1.jpg"></a>
<div id="layer1" style="display:none">
<a href="#" onclick="displayOneLayer(2); return false;"><img src="image1.jpg"></a>
<div id="layer2" style="display:none">
<a href="#" onclick="displayOneLayer(3); return false;"><img src="image1.jpg"></a>
<div id="layer3" style="display:none">
Hope this helps.
function displaylayer(layer,x) {
if (x==1) {
document.getElementById(layer).style.display="block"
}
else {
document.getElementById(layer).style.display="none"
}
}
And then I accessed the function this way :
<a href="#" onclick="displaylayer('layer2',1); return false"><img src="image1.jpg"></a>
...
Thanks again for the help from everyone.