473,890 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing array to new fuction

Hi Folk

I have the following function
var a = new Array(4);
a[0] = new Array(45); //status (on or off)
a[1] = new Array(45); //name of the region
a[2] = new Array(45); //on mouse over
a[3] = new Array(45); //on mouse out

a[0][0] = false;
.....snip
a[1][0] = "region name";
......snip
a[2][1] = new Array('x', 'b','c','d',); // outer islands
a[2][2] = new Array('h', 'x', 'x', 'n');
....snip
a[3][1] = new Array('a', 'b','c','d',); // outer islands
a[3][2] = new Array('h', 'h', 'n', 'n');
....snip

function Rx(i) {
var j;
var dd = new Array();
document.getEle mentById('r'+i) .checked ? j = 3 : j = 2;
dd = a[j][i];
si(dd);
}

function si() {
if (document.image s && (preloadFlag == true)) {
var img;
for (var i=0; i<si.arguments. length; i+=2) {
img = null;
if (document.layer s) {
img = findElement(si. arguments[i],0);
}
else {
img = document.images[si.arguments[i]];
}
if (img) {
img.src = si.arguments[i+1]+'.gif';
}
}
}
}

My problem is when I call the Rx(i) function, it passes the whole array (e.g. a[2][3]) as one variable to si and not an array,
therefore, si does not work. What am I doing wrong?

There are about 200 a[i][j] variables, some of which are arrays in themselves.

TIA

- Nicolaas

Jul 23 '05 #1
2 1570
windandwaves wrote:
Hi Folk [...] ...snip
a[3][1] = new Array('a', 'b','c','d',); // outer islands
You have a syntax error here -------^
a[3][2] = new Array('h', 'h', 'n', 'n');
...snip

function Rx(i) {
var j;
var dd = new Array();
document.getEle mentById('r'+i) .checked ? j = 3 : j = 2;
dd = a[j][i];
si(dd);
Insert:

alert(dd);

to see that dd is an array.
}

function si() {
if (document.image s && (preloadFlag == true)) {
var img;
for (var i=0; i<si.arguments. length; i+=2) {
img = null;
if (document.layer s) {
img = findElement(si. arguments[i],0);
}
else {
img = document.images[si.arguments[i]];


Here you are grabbing the arguments, but there is only one - the
entire array of what was formerly dd. Try:

...si.arguments[0][i]];

[...]

No warranty or guarantees provided.

--
Rob
Jul 23 '05 #2
RobG wrote:
windandwaves wrote:
Hi Folk

[...]
...snip
a[3][1] = new Array('a', 'b','c','d',); // outer islands


You have a syntax error here -------^
a[3][2] = new Array('h', 'h', 'n', 'n');
...snip

function Rx(i) {
var j;
var dd = new Array();
document.getEle mentById('r'+i) .checked ? j = 3 : j = 2;
dd = a[j][i];
si(dd);


Insert:

alert(dd);

to see that dd is an array.
}

function si() {
if (document.image s && (preloadFlag == true)) {
var img;
for (var i=0; i<si.arguments. length; i+=2) {
img = null;
if (document.layer s) {
img = findElement(si. arguments[i],0);
}
else {
img = document.images[si.arguments[i]];


Here you are grabbing the arguments, but there is only one - the
entire array of what was formerly dd. Try:

...si.arguments[0][i]];

[...]

No warranty or guarantees provided.

--
Rob


Two syntax errors.
Not much point to this:

function Rx(i) {
var j;
var dd = new Array();
document.getEle mentById('r'+i) .checked ? j = 3 : j = 2;
dd = a[j][i];
si(dd);
}

You've created a new array, assigned it to dd, and then overwritten
that with whatever was in the element a[j][i]. Why not just pass the
original reference?

si(a[j][i]);

As RobG hinted, you can't replace the arguments array (btw
'Function.argum ents' was deprecated in favor of simply 'arguments'
around 1998) with another array passed in there; it'll be treated as
one argument.

function Rx(i) {
var el;
if (el = document.getEle mentById('r' + i))
si(a[el.checked ? 3 : 2][i]);
}

function si(arr) {
if (document.image s
&& preloadFlag
&& typeof arr[0] != 'undefined') {
var img;
for (var i=0; i<arr.length; i+=2) {
img = null;
if (document.layer s) {
img = findElement(arr[i],0);
}
else {
img = document.images[arr[i]];
}
if (img) {
img.src = arr[i+1]+'.gif';
}
}
}
}

This sort of script is often made dramatically clearer (and more
efficient) by replacing the nested arrays with some sort of generic
object structure using named properties.

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1982
by: Tek9_AK | last post by:
I need to find a way to transfer all the values of an array inside a function out of the fuction into another array. IE function splice($filename){ if(file_exists($filename)){ $value=array("0"); // clear the array. $rows=file($filename); // break text file into a rows array for($num=0;$num < count($rows); ++$num){ $column=split(";",$rows); $value=$column;}}
2
2431
by: Tek9_AK | last post by:
I need to find a way to transfer all the values of an array inside a function out of the fuction into another array. IE function splice($filename){ if(file_exists($filename)){ $value=array("0"); // clear the array. $rows=file($filename); // break text file into a rows array for($num=0;$num < count($rows); ++$num){ $column=split(";",$rows); $value=$column;}}
8
3978
by: Alex Vinokur | last post by:
Various forms of argument passing ================================= C/C++ Performance Tests ======================= Using C/C++ Program Perfometer http://sourceforge.net/projects/cpp-perfometer http://alexvn.freeservers.com/s1/perfometer.html
58
10222
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
26
9645
by: JGH | last post by:
How can I check if a key is defined in an associative array? var users = new array(); users = "Joe Blow"; users = "John Doe"; users = "Jane Doe"; function isUser (userID) { if (?????)
4
5033
by: Pushkar Pradhan | last post by:
I want a function to execute another function, which I pass to it, sometimes it may be mm_6r6c_6r6c, mm_2r2c_2r2c, ... etc. thus this style. double exec_basecase(void (*func)(double *a, double *b, double *c), double *a, double *b, double *c, int numRowsA, int numColsA, int numColsB) { ...../*other code*/ func(a, b, c); ..... }
2
1608
by: spleen | last post by:
Hiya, Im a newbie to C so please excuse my ignorance... Ok, so I have several C files, with my functions in, one has main in of course! and I have 2 structs as outside of the funtions (therefore global?) in one of the files. I can pass my information into the structs with no major difficulties, that was easy! anyway now im trying to read from the structure into a
11
8145
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line number) which is the last line of the following sub routine: ' procedure modifies elements of array and assigns ' new reference (note ByVal) Sub FirstDouble(ByVal array As Integer()) Dim i As Integer
6
1775
by: effendi | last post by:
I have an array for of input names. Input1 , input 2 etc. Can I pass the input names in a loop like document.all.value="xxxx" The problem is document.all cannot be used in Safari/firefox, I tried using document.getElementById but my inputs do have any IDs. is there any way of accomplishing thsse.?
0
9975
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11212
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10799
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8004
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7154
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4255
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3263
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.