homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Passing A Single Argument
Passing A Single Argument To A Multiple Argument Functions

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

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?


Purple Martin

 2:45 am on Jan 6, 2004 (gmt 0)

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)

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)

I suggest you need something like-

function switchOn(layer) {

function switchOff(layer) {

function switchOnAll() {

... onclick="switchOn('layer1');" onmouseout...


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

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)

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";
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)

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) {
else {

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved