Click to See Complete Forum and Search --> : Populate JavaScript Array using Function


hismightiness
12-09-2003, 03:30 PM
I have to populate a JavaScript array using ASP. Now, this shouldn't be difficult, but because of the way I needed to lay out the page, the array cannot become filled until the end of the page, but the array need to be declared in the beginning. Therefore, I thought that filling the array using a function would suffice since the function can be implemented later on the page. Here is what I have so far:
/* fill variables */
var arrDrivers = new Array();
call popDrivers(arrDrivers);
var arrTrucks = new Array();
call popTrucks(arrTrucks);

Later in the page, I hae the functions laid out like so...
function popDrivers(arrDrivers){
//The ASP outputs numerous lines like this...
arrDrivers["6279"]="John B. Doe";
return arrDrivers();
}
Now, what am I doing wrong in trying to fill the arrays?

MichaelM
12-09-2003, 04:08 PM
Looks like you're treating the index of the array as if it were a string. JavaScript expects the index of an array to be an integer.

So
    arrDrivers["6279"]="John B. Doe";

Should be
    arrDrivers[6279]="John B. Doe";

hismightiness
12-09-2003, 04:30 PM
Thanks! I didn't realize that I was doing that. Howevr, I am still getting an error that I was hoping this post would resolve.

It is:
Line: 33
Error: Object Expected

Line 33 is this line:
var arrDrivers = new Array();