[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: variable assignment from child window



At 12:25 PM 3/13/96 +0000, John Ray wrote:
>I've set up user registration for my home page that takes input on a
>form in a child window called stat_window. Before opening the window I
>create a property of stat_window called nav for accessing the main
>Navigator window functions and properties with:
>
>stat_window.nav=self;
>
>So far so good. The problem is this: From the child window I call 
>a function in the nav window that needs to access the data that was 
>just entered in the child window form. I don't want to change the 
>function to accept arguments and pass the values unless absolutely 
>necessary. What I have done is changed the values of two global 
>variables (user_name and e_mail) in the Navigator window, from the 
>child window with the following.
>
>nav.user_name=<value from the form field>
>nav.e_mail=<value from the form field>

This is where you're getting into trouble.  There's a bug in JS that
afflicts frames (and I assume windows) in the following manner.  When you
change the parent's variable's from a child, you risk corruption.  I believe
it is extremely important to set the parent's variables WITHIN the parent
document.  If you set the value from the child and then the child is
destroyed (or corrupted itself), then the parent's value will be corrupted.
The best way to solve this is:

********parent window*************
function update(name,mail) {
  user_name = "" + name
  e_mail    = "" + mail
}

********stat_window (child)***********
function sendEm(form) {
  nav.update(form.name.value,form.mail.value)
}

And call this from the onChange or onSubmit method (or wherever you're doing
it now).

Hope this helps.
-Andy Augustine
JavaScript 411 -- http://www.freqgrafx.com/411/

--------------------------------------------------------------------
For help about the list, please send a message to 'majordomo@obscure.org'
with the message body 'help'. To unsubscribe, send a message to
'majordomo@obscure.org' with the message body 'unsubscribe javascript'.
List archives and pointer to FAQ: http://www.obscure.org/javascript/