Welcome to WebmasterWorld Guest from 54.205.74.11

Forum Moderators: open

Passing A Single Argument

Passing A Single Argument To A Multiple Argument Functions

   
8:49 pm on Jan 5, 2004 (gmt 0)

10+ Year Member



I've searched the web on a way to send a single arguemnt to a multiple arguement function; but I can only find a way of doing it with special math functions using a library add on. I have one function controlling multiple layers. I want the layers to display when clicked on a link, so far so good; but I want all the layers that have been selected to display instead of just the most recent layer to display. So I need to pass a single argument to a multi-argument fuction to turn switches for the layers off and on depending on what is chosen. Does that make sense?
2:45 am on Jan 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry no it doesn't make much sense. How are layers "selected"? Do they have checkboxes that you could get the values of? I don't really understand what you're trying to do.

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.

3:25 am on Jan 6, 2004 (gmt 0)

10+ Year Member



I'm not so hot at explaining things, so here is some of my code. I have a function :

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.

1:17 pm on Jan 6, 2004 (gmt 0)

10+ Year Member



I suggest you need something like-

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...

8:40 pm on Jan 6, 2004 (gmt 0)

10+ Year Member



Thanks for the thoughts. I tried something very similar; but it didn't recognize layer as "layer1" because I used the double quotes "..." instead of the single quotes '...' So I had :

<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]

9:05 pm on Jan 6, 2004 (gmt 0)

10+ Year Member



Looking at your code snippet, perhaps this is more of what you are looking for:

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.

1:14 am on Jan 7, 2004 (gmt 0)

10+ Year Member



I see what you're saying TrinkDog. I think I'll try and use that as a function letting the user decide how many layers there will be, and what will be on each layer. Ultimately I went with something close to what HocusPocus did; but I just used one function with two arguements :

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.

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month