# Setting Ajax.Updater update target to alternate window?

**URL:** <https://www.ruby-forum.com/t/setting-ajax-updater-update-target-to-alternate-window/75648>\
**Category:** Rails\
**Created:** [November 11, 2006, 10:52pm UTC](https://www.ruby-forum.com/t/setting-ajax-updater-update-target-to-alternate-window/75648 "2006-11-11T22:52:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [November 11, 2006, 10:52pm UTC](https://www.ruby-forum.com/t/setting-ajax-updater-update-target-to-alternate-window/75648/1 "2006-11-11T22:52:22Z")

</div>

I need to make a call to Ajax.Updater(container, url, options) where  
container needs to be a DOM element in another window.

So assuming my form is in window “X”, can I specify a DOM element in  
window “Y” as the update target for my AJAX call?

If I can, what is the correct syntax?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [November 11, 2006, 11:19pm UTC](https://www.ruby-forum.com/t/setting-ajax-updater-update-target-to-alternate-window/75648/2 "2006-11-11T23:19:16Z")

</div>

Alternatively, I’m interested in how to dynamically add a form to a  
document using the DOM in Javascript.

I’m trying

```
newForm = document.createElement('form');

```

but doesn’t seem to be showing up in the document forms array.

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [November 13, 2006, 6:25pm UTC](https://www.ruby-forum.com/t/setting-ajax-updater-update-target-to-alternate-window/75648/3 "2006-11-13T18:25:48Z")

</div>

I ended up with the Javascript function below.

This:

- Opens a popup
- Adds a DIV with wait message and graphic
- Submits the form request
- Eval’s the response from the form request which is something along the  
lines of:

page.assign(‘popup.location.href’, ‘…data…’)

which takes the output of the form submission and renders to the  
browser.

Wes

==========================================================================

function submit\_form\_to\_popup(form, popup\_window\_name, action) {  
form.action = action;  
popup = window.open(’’, popup\_window\_name, ‘width=800, height=700,  
left = 450, top = 100, resizable, scrollbars=yes’);  
wait\_image\_url = window.location.protocol + ‘//’ +  
window.location.host + ‘/images/indicator\_verybig.gif’;

//Create a DIV in the popup window and populate it with the AJAX wait  
message and graphic.  
newDiv = popup.document.createElement(‘div’);  
newDiv.setAttribute(‘id’, ‘pdf’);  
newDiv.setAttribute(‘style’, ‘margin-top: 250px; text-align:  
center;’);  
newDiv.innerHTML = ‘Please wait while your forms are  
generated  
  
 ![]()’;  
popup.document.body.appendChild(newDiv);

//Submit the form asynchronously and execute Javascript returned from  
the action.  
new Ajax.Request(form.action, { asynchronous: true, method:  
‘post’, parameters: Form.serialize(form), evalScripts:  
true,  
onSuccess: function(request)  
{eval(request.responseText);}  
});  
return false;  
}
