Is this really impossible?

Has anyone ever updated a form textbox field in a parent window from a
child window? I've asked this looked for and question in various places
and have not received any responses. Is this impossible to do?

I've tried link_to_remote and link_to_function and none of this is
updating my parent window for me. I thought that link_to_function would
be a good bet, but my Javascript isn't doing anything - either I get an
XML attribute error or no errors and no updates.

Have I really hit the wall and need to abandon this idea?

I've never heard of any way to do this client-side (in the browser). I
would set the parent window to use link_to_remote to send the
information to the server, and then periodically have the child check
back with the server for updates from the parent..

Bryan M. wrote:

I've never heard of any way to do this client-side (in the browser). I
would set the parent window to use link_to_remote to send the
information to the server, and then periodically have the child check
back with the server for updates from the parent..

Thanks for your reply. The problem is that this is part of a form and
so if a user updates part of the form and then opens the pop-up box, the
rest of the form details will be lost.

AFAIK, yes. The parent window can address the child because it
has a handle to it -- the var from e.g.

  var child_window = window.open("child_form.html","child_window",args);

So the parent can initiate interaction with the child, but not the other
way around. You could have the parent "poll" the child every second
or two for changes. Or as mentioned write the child's data directly to
the server asynchronously.

HTH,

Hassan Schroeder wrote:

AFAIK, yes. The parent window can address the child because it
has a handle to it -- the var from e.g.

  var child_window = window.open("child_form.html","child_window",args);

I had really thought that I could use link_to with a javascript
function, but I'm not finding working code.

So if I abandon that idea, could would there be a way to utilize a
partial just for that textarea and have that partial update, but not
the rest of the form? Will that work?

Oh, the bad code that I can see coming now.

That's what link_to_function does. And the child window can access its
parent. I've done this in the past by having a function in the parent
window that did whatever I needed and then calling
opener.some_function() from the child window.

Fred

That's what link_to_function does. And the child window can access its
parent. I've done this in the past by having a function in the parent
window that did whatever I needed and then calling
opener.some_function() from the child window.

Almost forgot, one big caveat to that: both pages need to be served
from the same domain.

Fred

well, son of a gun. "opener" is the magic word :slight_smile:

Is that well-supported across the major browsers?

Frederick Cheung wrote:

That's what link_to_function does. And the child window can access its
parent. I've done this in �the past by having a function in the parent
window that did whatever I needed and then calling
opener.some_function() from the child window.

Almost forgot, one big caveat to that: both pages need to be served
from the same domain.

Same domain meaning the same controller or literally both in the same
www.domain.com?

The pop up has a different model & controller than the parent. But my
thought was that the Javascript shouldn't care about that and only deal
with parent and child windows.

This is what I had, but it doesn't update my parent. Any thoughts on
how to make this code work?

<%=link_to_function("the link",
"window.opener.document.getElementById('item_field').value =
'#{@item_codes}';self.close() %>

Frederick Cheung wrote:

That's what link_to_function does. And the child window can access
its
parent. I've done this in �the past by having a function in the
parent
window that did whatever I needed and then calling
opener.some_function() from the child window.

Almost forgot, one big caveat to that: both pages need to be served
from the same domain.

Same domain meaning the same controller or literally both in the same
www.domain.com?

Same combination of domain name, protocol (http or https) and port

The pop up has a different model & controller than the parent. But my
thought was that the Javascript shouldn't care about that and only
deal
with parent and child windows.

This is what I had, but it doesn't update my parent. Any thoughts on
how to make this code work?

<%=link_to_function("the link",
"window.opener.document.getElementById('item_field').value =
'#{@item_codes}';self.close() %>

That works for me (alhough i used
opener.document.forms['answer_form'].reply.value = 'xyz')
Also self.close() isn't going to do anything (since javascript uses
this not self and because in this context this will be the link itself).

Fred

opener.some_function() from the child window.

well, son of a gun. "opener" is the magic word :slight_smile:

Is that well-supported across the major browsers?

As far as I know.

Fred

Thanks for all of the great help!!!

I am so close to getting this to work. This works in FF, IE and Safari.

Here's the final code that I used to put the values into the text area.

<%=link_to_function("[close window]",
"opener.document.getElementById('form_field').value =
'#{@list}';self.close();") %>

The pop up window that opens contains partials for the drag and drop. I
have the initial select list, the list of items that have been selected
and the area for dragging unwanted items.

The only hiccup now is that for me to get this to work, I have to have
the link_to_function in the partial with the selected values otherwise
the textarea is not updated.

Any thoughts?