# How to update an iframe element with form\_remote\_tag?

**URL:** <https://www.ruby-forum.com/t/how-to-update-an-iframe-element-with-form-remote-tag/117814>\
**Category:** Rails\
**Created:** [October 20, 2007, 7:11pm UTC](https://www.ruby-forum.com/t/how-to-update-an-iframe-element-with-form-remote-tag/117814 "2007-10-20T19:11:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fxp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a5b964/32.png) [@fxp](https://www.ruby-forum.com/u/fxp)\
**Post date:** [October 20, 2007, 7:11pm UTC](https://www.ruby-forum.com/t/how-to-update-an-iframe-element-with-form-remote-tag/117814/1 "2007-10-20T19:11:49Z")

</div>

I have a view with an iframe in it that contains a list of messages. I  
would like to update this list from a form in my view that I’ve created  
with form\_remote\_tag.

My code is structured like this right now:  
#iframe\_view.rhtml#

#index.rhtml#

\<% form\_remote\_tag :update=\>“message\_list” :url=\>“post\_message” %\>  
\<%= submit\_tag “Post” %\>

The problem is that when I submit the form it doesn’t update the  
message\_list div. I assume that’s because it’s in a separate document.  
What should I put in :update so that it will update the message\_list  
div?

---

<div class="post-metadata">

**Author:** ![fxp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a5b964/32.png) [@fxp](https://www.ruby-forum.com/u/fxp)\
**Post date:** [October 21, 2007, 3:23am UTC](https://www.ruby-forum.com/t/how-to-update-an-iframe-element-with-form-remote-tag/117814/2 "2007-10-21T03:23:16Z")

</div>

I found a solution–maybe not the best one. For anyone that runs into  
the same problem what I did was I created a hidden

 and set that as  
the :update parameter, then used :complete to call a javascript function  
that would copy the returned message into the iframe from the hidden
.

---

<div class="post-metadata">

**Author:** ![fxp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a5b964/32.png) [@fxp](https://www.ruby-forum.com/u/fxp)\
**Post date:** [October 21, 2007, 3:40am UTC](https://www.ruby-forum.com/t/how-to-update-an-iframe-element-with-form-remote-tag/117814/3 "2007-10-21T03:40:46Z")

</div>

Why can’t you give the iframe an id and just use rjs to insert the  
content from the controller?

---

<div class="post-metadata">

**Author:** ![fxp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a5b964/32.png) [@fxp](https://www.ruby-forum.com/u/fxp)\
**Post date:** [March 1, 2008, 5:40am UTC](https://www.ruby-forum.com/t/how-to-update-an-iframe-element-with-form-remote-tag/117814/4 "2008-03-01T05:40:58Z")

</div>

Corey M. wrote:

> I have a iframe that renders a partial (containing a list) using a  
> “url\_for” in the src attribute of the iframe. The list provides the  
> user the ability to move list items up or down in the list, which I’d  
> then like to update by re-rendering the partial. Problem is all my  
> “link\_to\_remote…” links in the list don’t function now that the partial  
> is rendered in the iframe. I’m guessing that’s because the  
> link\_to\_remotes are attempting to update a div that wraps the iframe but  
> I wouldn’t know what else to update. Why doesn’t just updating or  
> re-rendering the partial update the partial within the iframe?

You’ll have to create a special layout for the iframe that wraps  
a simple HTML head and body, with the head containing a link  
to prototype.js.

May I ask why you’re using an iframe? Could you get away with  
an “overflow: auto” div?

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![fxp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a5b964/32.png) [@fxp](https://www.ruby-forum.com/u/fxp)\
**Post date:** [February 29, 2008, 9:10pm UTC](https://www.ruby-forum.com/t/how-to-update-an-iframe-element-with-form-remote-tag/117814/5 "2008-02-29T21:10:28Z")

</div>

William P. wrote:

> Why can’t you give the iframe an id and just use rjs to insert the  
> content from the controller?

This is the same dilema I have and I like what this solution poses  
however, I’m still not great an using javascript within rails. I’m good  
with javascript just not intermixing.

I have a iframe that renders a partial (containing a list) using a  
“url\_for” in the src attribute of the iframe. The list provides the  
user the ability to move list items up or down in the list, which I’d  
then like to update by re-rendering the partial. Problem is all my  
“link\_to\_remote…” links in the list don’t function now that the partial  
is rendered in the iframe. I’m guessing that’s because the  
link\_to\_remotes are attempting to update a div that wraps the iframe but  
I wouldn’t know what else to update. Why doesn’t just updating or  
re-rendering the partial update the partial within the iframe?

---

<div class="post-metadata">

**Author:** ![fxp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a5b964/32.png) [@fxp](https://www.ruby-forum.com/u/fxp)\
**Post date:** [March 3, 2008, 4:10pm UTC](https://www.ruby-forum.com/t/how-to-update-an-iframe-element-with-form-remote-tag/117814/6 "2008-03-03T16:10:05Z")

</div>

Mark Reginald J. wrote:

> You’ll have to create a special layout for the iframe that wraps  
> a simple HTML head and body, with the head containing a link  
> to prototype.js.
> 
> May I ask why you’re using an iframe? Could you get away with  
> an “overflow: auto” div?
> 
> –  
> We develop, watch us RoR, in numbers too big to ignore.

I ended up using exactly that solution (div with overflow). I was only  
looking for the scrolling ability however, once I had encountered the  
iframe issue, it became my mission to resolve the problem that way or at  
least get a better understanding of why it behaved the way it did.

Thanks for the help,
