Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding to a Multidimensional array in parent window 2

Status
Not open for further replies.
Joined
Mar 3, 2006
Messages
25
My opener window has a multidimensional array that I want the child window to add to. I can watch the child add the array to the opener (with no error messages) but after the child is closed and I check the opener, only the object of the array I added is retained. The fields and values are gone.

For example:
In the parent is the array prt:
prt['A']['01']['descr']='John'
prt['A']['01']['city']='Miami'
prt['A']['02']['descr']='Ralph'
prt['B']['DR']['descr']='Sara'
prt['B']['DR']['city']='LA'
. . . .

From the child window I'm running
----------------------------------------------
opener.prt['A']['09'] = new Array();
opener.prt['A']['09']['descr']='Moe';
opener.prt['A']['09']['city']='Juneville';
opener.prt['A']['09']['color']='red';
----------------------------------------------

Before I close the child I can view the parent array from the debugger (within the child) and it shows all of these as being added. After the child window closes and I run the debugger on the opener window the only thing added to the prt array is prt['A']['09'] as an object with a length of 'error'. I've also tried "window.opener" instead of just "opener" with the same results.

Any help or suggestions would be greatly appreciated.
 
There's probably a shorter way, but give this a whirl, based upon a hunch.

In the opener window, add a function:

Code:
function newArray(varToAddArrayTo) {
   varToAddArrayTo = new Array();
}

and then change this:

Code:
opener.prt['A']['09'] = new Array();

to this:

Code:
opener.newArray(opener.prt['A']['09']);

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
OK - convaluted, but this does work (I've tested it). It's also scalable - which is why it's not simpler ;-)

Add this function to your opener:

Code:
function newArray(arrayName) {
	var theArray = window[arrayName];
	for (var loop=1; loop<arguments.length-1; loop++) theArray = theArray[arguments[loop]];
	theArray[arguments[arguments.length-1]] = new Array();
}

and then replace this:

Code:
opener.prt['A']['09'] = new Array();

with this:

Code:
opener.newArray('prt', 'A', '09');

One thing to note - this only happens in IE - not in Firefox.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Dan, You Rock!! Works Excellent.

I tried this in Firefox and it works fine. Did you mean my original code would have worked fine in Firefox? I always write for IE and Mozilla(Firefox) but I debug in IE first since I seem to have more hangups to deal in IE.

Rois
 
Yes - your original code would work fine in Firefox - just not IE.

If you need any explanation of the code, just ask.

I quite liked solving this one - something meaty to get my teeth into at the end of a slow day ;-)

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top