...

View Full Version : Arrays in a function



caballonegro
07-28-2002, 12:31 AM
Hello
I'm beginner of java scripting and have a little problem

In my html file i define a array



mypics=new Array(
"images/zulauf_100.jpg",
"images/zulauf_450_S.jpg",

"images/ablauf_100.jpg",
"images/ablauf_450_S.jpg"
)


in a separate javascriptfile i have a function


function doanything()
{
i=0;
anzahl=mypics.length;
while (i < (anzahl))
{
document.writeln(mypics[i] + "<br>");
i++;
}

}


but this not work.
If both codings in the same htmlfile it works.
may be it works there because the array is global.

I think the problem is to transfer this array conntent to an external function.
How is the right way to transfer an array to a function in a separate javascriptfile

thanks

Susanna

Vermelh0
07-28-2002, 01:03 AM
change your function to this:
------------------------------------
function doanything(array)
{
for (i=0; i < array.length; i++)
{
document.writeln(array[i] + "<br>");
}
}

and call it using this syntax:
----------------------------------
doanything(mypics);

Later,
V



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum