# Help with RJS

**URL:** <https://www.ruby-forum.com/t/help-with-rjs/118964>\
**Category:** Rails\
**Created:** [November 1, 2007, 7:29pm UTC](https://www.ruby-forum.com/t/help-with-rjs/118964 "2007-11-01T19:29:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![totallygirl212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5e925/32.png) [@totallygirl212](https://www.ruby-forum.com/u/totallygirl212)\
**Post date:** [November 1, 2007, 7:29pm UTC](https://www.ruby-forum.com/t/help-with-rjs/118964/1 "2007-11-01T19:29:27Z")

</div>

Hi guys

I’m trying to use rjs to access a tag property. For example,

How do I get the value of trogdor\_id with rjs? Thanks!

---

<div class="post-metadata">

**Author:** ![totallygirl212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5e925/32.png) [@totallygirl212](https://www.ruby-forum.com/u/totallygirl212)\
**Post date:** [November 1, 2007, 10:59pm UTC](https://www.ruby-forum.com/t/help-with-rjs/118964/2 "2007-11-01T22:59:38Z")

</div>

This should work:

page[:foo][:trogdor\_id]

-Bill

---

<div class="post-metadata">

**Author:** ![totallygirl212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5e925/32.png) [@totallygirl212](https://www.ruby-forum.com/u/totallygirl212)\
**Post date:** [November 1, 2007, 11:06pm UTC](https://www.ruby-forum.com/t/help-with-rjs/118964/3 "2007-11-01T23:06:57Z")

</div>

Thanks so much for the reply William!

I’m getting an error when converting to string. This is my code below:

html:

blah blah

rjs:  
testing\_id = page[:theDivName][:trogdor]

page.replace\_html(“replacement\_div”,  
:partial =\> “some\_partial”,  
:locals =\> {:passing\_testing\_id =\> testing\_id  
})  
\_some\_partial:

This is the testing\_id: \<%= testing\_id %\>

> This should work:
> 
> page[:foo][:trogdor\_id]
> 
> -Bill

---

<div class="post-metadata">

**Author:** ![totallygirl212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5e925/32.png) [@totallygirl212](https://www.ruby-forum.com/u/totallygirl212)\
**Post date:** [November 1, 2007, 11:29pm UTC](https://www.ruby-forum.com/t/help-with-rjs/118964/4 "2007-11-01T23:29:55Z")

</div>

Thanks again bill. Would you have an example of how to do that?

William P. wrote:

> That won’t work because rjs is just converted to javascript then sent to  
> the browser, so your variable would never have that id in it. You will  
> need to pass the trogdor id in a link or as a hidden form variable.
> 
> -Bill

---

<div class="post-metadata">

**Author:** ![totallygirl212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5e925/32.png) [@totallygirl212](https://www.ruby-forum.com/u/totallygirl212)\
**Post date:** [November 1, 2007, 11:35pm UTC](https://www.ruby-forum.com/t/help-with-rjs/118964/5 "2007-11-01T23:35:56Z")

</div>

Sure, if the user is clicking on a link to trigger the action then this  
works:

\<%= link\_to\_remote ‘Click Me’, :url =\> {:controller =\> ‘somecontroller’,  
:action =\> ‘someaction’, :trogdor\_id =\> ‘a\_trogdor\_id’} %\>

Now you can access it as params[:trogdor\_id]. You could also just use  
:id instead of trogdor\_id unless it’s being used as something else. I  
assume this would be done in a loop setting trogdor\_id on each  
iteration. If this is part of a form then:

\<%= hidden\_field\_tag :trogdor\_id, ‘a\_trogdor\_id’ -%\>

Hope this helps.

-Bill

---

<div class="post-metadata">

**Author:** ![totallygirl212](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5e925/32.png) [@totallygirl212](https://www.ruby-forum.com/u/totallygirl212)\
**Post date:** [November 1, 2007, 11:13pm UTC](https://www.ruby-forum.com/t/help-with-rjs/118964/6 "2007-11-01T23:13:04Z")

</div>

That won’t work because rjs is just converted to javascript then sent to  
the browser, so your variable would never have that id in it. You will  
need to pass the trogdor id in a link or as a hidden form variable.

-Bill
