Click to See Complete Forum and Search --> : Java Arguements question


Ruler
September 12th, 2002, 04:34 PM
I have written a script that moves a navbar at the side of my web-site.

I have multiple layers with links on and it moves the layers to show the relavent links and the nav-bar slides in and out with a nice little sound.

The problem is that the code will be very long if i complete with out variables in it and i dont know how to use the variables in the function arguement. Also i dont know if what i am trying to do is possible.

I want to use a function arguement instead of a layer name. So as follows.
I currently have:

fucntion moveout() {
<code>
document.all.Services.style.posLeft = 72;
<code>
}

Is it possible to have:

fucntion moveout(<Layer>) {
<code>
document.all.<layer>.style.posLeft = 72;
<code>
}

If so how? PLease help.

Cheers
-Ruler-

Waldo2k2
September 12th, 2002, 07:42 PM
i have had to do something similar. Now the syntax for what I'm about to give you is correct, but It seems to be quirky...unless it's just me. Your implementation seems lightweight enough that you won't run into the problems i've had.

var layer;
function moveOut(layer)
{
if (document.all)
{
document.all[layer].style.posLeft=72;
}
if (document.GetElementById) //for IE5+ and NS6+
{
document.GetElementById(layer).style.posLeft=72;
}
}

unfortuneatly off the top of my head i can't remember NS4 code to stick in that function...but you can mess with that later. Good Luck.

Ruler
September 14th, 2002, 09:39 AM
Thankyou for the input but i still ahve a problem with the code i get an error saying:

Error: 'document.all[...].style' is not an object

i used moveout('Services'); as the function

Does anyone have any further input please.

Waldo2k2
September 14th, 2002, 01:39 PM
I forgot...using document.all[whatever].style.posLeft just accesses a memory location. To create an object, do this:

var oObj;
var layer;
function moveOut(layer)
{
if (document.all)
{
oObj=document.all[layer].style;
oObj.posLeft=72;
}
if (document.GetElementById) //for IE5+ and NS6+
{
oObj=document.GetElementById(layer).style;
oObj.posLeft=72;
}
}

give that a shot