# Update a div

**URL:** <https://www.ruby-forum.com/t/update-a-div/118106>\
**Category:** Rails\
**Created:** [October 23, 2007, 10:29pm UTC](https://www.ruby-forum.com/t/update-a-div/118106 "2007-10-23T22:29:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [October 23, 2007, 10:29pm UTC](https://www.ruby-forum.com/t/update-a-div/118106/1 "2007-10-23T22:29:57Z")

</div>

I have this list of users that I want to include in a group. I choose  
these users from a larger group - all the employees for a company , for  
example. I have both lists displayed on the page, the thing is that when  
I choose a user to include in my list I want to have that user shown in  
the list (update that list) but also have that user taken out of the  
other list. So basically I need to update two divs. I am using a  
form\_remote\_tag to :update the one div, but how do I update the second.  
Is there a way to update two divs as a result of an action? thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [October 24, 2007, 1:56am UTC](https://www.ruby-forum.com/t/update-a-div/118106/2 "2007-10-24T01:56:23Z")

</div>

Shandy N. wrote:

> Is there a way to update two divs as a result of an action? thanks,

RJS templates is one:

page.insert\_html :bottom, ‘thoughts’, :partial =\> ‘thought’  
page.visual\_effect :highlight, ‘thoughts’  
page.form.reset ‘thought-form’

This tutorial is long-winded but it’ll give you the basics:  
[http://ajax.stealthsettings.com/rjs-templates-for-rails/rjs-templates-for-rails-what-is-rjs/](http://ajax.stealthsettings.com/rjs-templates-for-rails/rjs-templates-for-rails-what-is-rjs/)

Then check out the docs:  
[http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html)

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [October 24, 2007, 10:08am UTC](https://www.ruby-forum.com/t/update-a-div/118106/3 "2007-10-24T10:08:38Z")

</div>

Shandy N. wrote:

> I have this list of users that I want to include in a group. I choose  
> these users from a larger group - all the employees for a company , for  
> example. I have both lists displayed on the page, the thing is that when  
> I choose a user to include in my list I want to have that user shown in  
> the list (update that list) but also have that user taken out of the  
> other list. So basically I need to update two divs. I am using a  
> form\_remote\_tag to :update the one div, but how do I update the second.  
> Is there a way to update two divs as a result of an action? thanks,
> 
> -S

Hi  
You can update two divs using :update =\>“div1,div2” in form\_remote\_tag  
and also by using  
render :update do |page|  
page.replace\_html ‘div1’, :partial =\> ‘file1’  
page.replace\_html ‘div2’, :partial =\> ‘file2’

in the controller

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [October 25, 2007, 4:58pm UTC](https://www.ruby-forum.com/t/update-a-div/118106/4 "2007-10-25T16:58:33Z")

</div>

Abhi M. wrote:

> Shandy N. wrote:
> 
> > I have this list of users that I want to include in a group. I choose  
> > these users from a larger group - all the employees for a company , for  
> > example. I have both lists displayed on the page, the thing is that when  
> > I choose a user to include in my list I want to have that user shown in  
> > the list (update that list) but also have that user taken out of the  
> > other list. So basically I need to update two divs. I am using a  
> > form\_remote\_tag to :update the one div, but how do I update the second.  
> > Is there a way to update two divs as a result of an action? thanks,
> > 
> > -S
> 
> Hi  
> You can update two divs using :update =\>“div1,div2” in form\_remote\_tag  
> and also by using  
> render :update do |page|  
> page.replace\_html ‘div1’, :partial =\> ‘file1’  
> page.replace\_html ‘div2’, :partial =\> ‘file2’
> 
> in the controller

This doesn’t work at all, at least not for me. I have a form\_remote\_tag  
with :update =\> ‘div1, div2’ and then in my controller I have the above  
code. If I leave off the :update, my button for the form act as if they  
haven’t been hit and with the update I get the same behavior. Is there  
something that I’m missing? Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [October 25, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/update-a-div/118106/5 "2007-10-25T17:28:19Z")

</div>

Shandy N. wrote:

> This doesn’t work at all, at least not for me. I have a form\_remote\_tag  
> with :update =\> ‘div1, div2’ and then in my controller I have the above  
> code. If I leave off the :update, my button for the form act as if they  
> haven’t been hit and with the update I get the same behavior. Is there  
> something that I’m missing? Thanks,
> 
> -S

I take that back, it is working - kinda, but I think my issue is in my  
code seperate then from your code Abhi. I removed the :update in the  
form tags and that seemed to help a lot. Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [October 25, 2007, 7:58pm UTC](https://www.ruby-forum.com/t/update-a-div/118106/6 "2007-10-25T19:58:36Z")

</div>

Shandy N. wrote:  
I removed the :update in the

> form tags and that seemed to help a lot. Thanks,

Correct. When you use RJS templates you should not specify the :update  
argument in your Ajax calls.
