Forum Moderators: open

Message Too Old, No Replies

Trying for Dynamic Array

         

kmbarz

4:06 am on Aug 20, 2004 (gmt 0)

10+ Year Member



I'm trying for an array that will grow as the user enters more data:

<script language="JavaScript">
var DPArray = new Array();
var DPCount = 0;

function DPAdd_onclick()
{
DPArray[DPCount] = new Array();
DPArray[DPCount][0] = formvariable1;
DPArray[DPCount][1] = formvariable2;
...
DPCount++;
}
...

The idea is that form data will fill the array and the user can add as many records as needed while getting visual feedback on the page. So the feedback works, but the DPArray[DPCount] arrays go out of scope so I can't use this array to write to my database later in the process.

So is there anyway to force DPArray[DPCount] to be global from within the function? (like I can do in other languages)
Thanks

Bernard Marx

6:51 am on Aug 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> is there anyway to force DPArray[DPCount] to be global from within the function?

The problem must be something else.
In the posted code, each DPArray[DPCount] is already a global reference, since DPArray is global, and each subarray is an indexed property of that.