# Javascript pop window from form how to update field back to main form

**URL:** <https://www.ruby-forum.com/t/javascript-pop-window-from-form-how-to-update-field-back-to-main-form/129001>\
**Category:** Rails\
**Created:** [February 13, 2008, 1:14pm UTC](https://www.ruby-forum.com/t/javascript-pop-window-from-form-how-to-update-field-back-to-main-form/129001 "2008-02-13T13:14:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KTU](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecae2f/32.png) [@KTU](https://www.ruby-forum.com/u/KTU)\
**Post date:** [February 13, 2008, 1:14pm UTC](https://www.ruby-forum.com/t/javascript-pop-window-from-form-how-to-update-field-back-to-main-form/129001/1 "2008-02-13T13:14:47Z")

</div>

Hi

I have question where I run web form. Now on this form I have one  
field with link select user.

This link will pop up new window with javascript and on this window I  
have form with items  
which end user can select. Once selection is done end user press  
button Select User.

Now I need to close that javascipt window and send back value of that  
selection back to form  
and to the field which has textbox for that value.

Is this possible ?

---

<div class="post-metadata">

**Author:** ![KTU](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecae2f/32.png) [@KTU](https://www.ruby-forum.com/u/KTU)\
**Post date:** [May 2, 2008, 6:22pm UTC](https://www.ruby-forum.com/t/javascript-pop-window-from-form-how-to-update-field-back-to-main-form/129001/2 "2008-05-02T18:22:36Z")

</div>

Jesus bernardo Ruiz flores wrote:

\<%=link\_to\_function("#{person.apellido}

> #{person.nombre}",  
> "set\_value(‘voip\_person\_id’,’#{person.id}’);  
> set\_value(‘voip\_id\_servicio’,’#{person.id\_cliente}’);  
> set\_value(‘voip\_contrato’,’#{person.id\_cliente}’);  
> set\_value(‘voip\_contacts\_attributes\_\_nombre’,’#{person.nombre.capitalize}’);  
> set\_value(‘voip\_contacts\_attributes\_\_apellido’,’#{person.apellido.capitalize}’);  
> set\_value(‘voip\_contacts\_attributes\_\_razon\_social’,’#{person.razon\_social}’);  
> ")%\>
> 
> And this is the function set\_value inside  
> public/javascripts/application.js
> 
> function set\_value(id,value)  
> {  
> opener.document.getElementById(id).value=value;  
> window.close();  
> }

I am trying to implement your solution, but I don’t see any updates.

Here’s my code:

\<%= link\_to\_function(“function\_link”, "set\_value(‘div\_area\_form’,  
‘#{@item\_codes}’); ") %\>

The view source of the javascript shows this:

function\_link

Any ideas?

---

<div class="post-metadata">

**Author:** ![KTU](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecae2f/32.png) [@KTU](https://www.ruby-forum.com/u/KTU)\
**Post date:** [April 9, 2008, 4:40pm UTC](https://www.ruby-forum.com/t/javascript-pop-window-from-form-how-to-update-field-back-to-main-form/129001/3 "2008-04-09T16:40:08Z")

</div>

KTU wrote:

> Hi
> 
> I have question where I run web form. Now on this form I have one  
> field with link select user.
> 
> This link will pop up new window with javascript and on this window I  
> have form with items  
> which end user can select. Once selection is done end user press  
> button Select User.
> 
> Now I need to close that javascipt window and send back value of that  
> selection back to form  
> and to the field which has textbox for that value.
> 
> Is this possible ?

Hi this i what I did, to select and user from one form and update a  
select box in another form:

This is the code for the view that show all the users found:

 \<% form\_tag person\_find\_show\_select\_path, :method=\>"get" do%\> \<%end%\> \<% switch=false for person in @persons %\> \<% switch=!switch %\>"\> \<% end %\>

| Buscar Usuario: | \<%=select\_tag "busqueda","Nombre CompletoRazon SocialId ServicioId ClienteContrato"%\> \<%=hidden\_field\_tag :id, "13"%\> | \<%=text\_field\_tag :search, params[:search]%\> | \<%=submit\_tag "Buscar", :name=\>nil%\> |
| Nombre | ID Cliente |
| --- | --- |
| \<%=link\_to\_function("#{person.apellido} #{person.nombre}", "set\_value('voip\_person\_id','#{person.id}'); set\_value('voip\_id\_servicio','#{person.id\_cliente}'); set\_value('voip\_contrato','#{person.id\_cliente}'); set\_value('voip\_contacts\_attributes\_\_nombre','#{person.nombre.capitalize}'); set\_value('voip\_contacts\_attributes\_\_apellido','#{person.apellido.capitalize}'); set\_value('voip\_contacts\_attributes\_\_razon\_social','#{person.razon\_social}'); ")%\> | \<%=person.id\_cliente%\> |

And this is the function set\_value inside  
public/javascripts/application.js

function set\_value(id,value)  
{  
opener.document.getElementById(id).value=value;  
window.close();  
}

Hope this help
