Page 1 of 1

pass a pointer to an array in a JS function

Posted: Mon Apr 17, 2006 12:03 pm
by Burrito
I am creating a function in JS that will loop over checkboxes and check them if necessary.

I have created a few arrays for the different sets of checkboxes above my function and I need to point to those arrays in one of my function arguments.

I know I"ve done this before but I can't remember where or how...here's an ex:

Code: Select all

var someArr = Array('one','two','three');
var someOtherArr = Array('four','five','six');
function checkAll(obj,whichArr)
{
   if(obj.checked)
   {
      for(i=0;i<whichArr.length;i++)
         //etc...
   }
}
unforutnately I can't pass the array variable itself in my function call because it's not defined at that point. I'm passing it as a string (the name of the array) and it's not flying.

I've also tried creating an associative multidimensional array and passing the name of the array I need to loop as the key of my array...still no go.

any ideas?

thx,

Burr

Posted: Mon Apr 17, 2006 12:06 pm
by feyd

Code: Select all

checkAll(someObj, someArr);

Posted: Mon Apr 17, 2006 12:12 pm
by Burrito
yeah I wish it were that easy, however, I need to be able to select which array I want to check all of the boxes dynamically.

I think I have it figured though.

I did end up using the multidimensional associative array.