View Full Version : Using array variable in 2 windows
balltom
01-26-2003, 11:52 PM
Hello folks,
I am definitively learning all this, so be nice with me
:(
I have a main window where I manipulate an Array.
I would like to be able to change some values of this array using a Popup window called from my main window (with check boxes in it).
I tried to declare my array as global in the main window:
<script>
var list = New Array
list[list.lenght] = New Array("Apple", "Red", 4)
list[list.lenght] = New Array("Grappes", "Green", 30)
etc.
</script>
And I want to use and modifiate this array in my pop up:
<script>
...
list[1][2] = 6
...
</script>
But I don't know if I can use the same variable name or if I need to declare it again... :confused:
So far I got "list is null" or other kind of crap...
Be nice with me, tell me how to do it.
Thanks in advance.
Tom
CRASH_OVERRIDE
01-26-2003, 11:56 PM
you spelled 'length' wrong as 'lenght' ;)
I dont know the exact procedure, but you can probably access it by something using the 'parent' or 'opener' property.
balltom
01-27-2003, 12:43 AM
Thanks Crash. Quick response!
In fact I misspelt when I copied the code in the message.
In my original code, it is spelt right.
I figured the opener or parent property might work. But when I am using them, I got a "variable not defined" error.
How should I use them?
Any tutorial somewhere or your help?
should I just use parent.list[x][y] or opener.list[x][y].
Or any declaration to make before?
Thanks a lot!
CRASH_OVERRIDE
01-27-2003, 01:05 AM
Did you make sure that the parent property was called from the window object? Then it might work the way you say, like window.parent.list[x][y], but I cant guarentee anything as I have never attempted anything like this.
Can I get an expert please?
An alternative would be to use ASP and querystrings instead, but I dont know if those can handle arrays...
balltom
01-27-2003, 01:15 AM
Doesn't work either. :(
Here is my parent page:
<script language=JavaScript>
list=new Array()
list[list.length]=new Array("/music/1999.mid","1999", 1)
list[list.length]=new Array("/music/50s_60s.mid","50s_60s", 1)
list[list.length]=new Array("/music/ABBA - Dancinqueen.mid","ABBA - Dancinqueen", 1)
list[list.length]=new Array("/music/addictedtolove.mid","addictedtolove", 1)
list[list.length]=new Array("/music/aladdin.mid","aladdin", 1)
</script>
<script>
...
other functions using this array and that work...
...
</script>
here is the script in the popup
<SCRIPT language=JavaScript>
function check_out(form_, name) {
var box, e = 0, grp = form_[name]
while (box = grp[e++]) {
if (eval(box.checked)==true){
parent.list[e-1][2]=1
}
else {
parent.list[e-1][2]=0
}
}
window.close()
}
</script>
when I use the function check_out()
I got the following error message: "parent.list is null or not an object"
:confused: :confused: :confused:
CRASH_OVERRIDE
01-27-2003, 01:18 AM
That's because list isnt an object- you would need a collection or a method to draw the array data from the parent window.
glenngv
01-27-2003, 01:51 AM
use:
opener.list[e-1][2] = 1;
just make sure the index of the array is not out of bounds.
you might want to check first if the opener window is closed or not before setting the array:
if (opener && !opener.closed) opener.list[e-1][2] = 1;
CRASH_OVERRIDE
01-27-2003, 01:53 AM
All right people, stop making me feel brain dead. :D
balltom
01-27-2003, 04:43 AM
Awesome... it works.:thumbsup:
But Crash you don't have to feel bad. You suggested 'opener' or 'parent'. I just picked the wrong one.:o
You guys are so great!
Thanks a bunch.
Tom
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.