# Is a javascript object accessible in the .rjs file (AJAX)?

**URL:** <https://www.ruby-forum.com/t/is-a-javascript-object-accessible-in-the-rjs-file-ajax/91477>\
**Category:** Rails\
**Created:** [April 9, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/is-a-javascript-object-accessible-in-the-rjs-file-ajax/91477 "2007-04-09T17:24:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/51bf81/32.png) [@luca](https://www.ruby-forum.com/u/luca)\
**Post date:** [April 9, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/is-a-javascript-object-accessible-in-the-rjs-file-ajax/91477/1 "2007-04-09T17:24:47Z")

</div>

Hi All

In my rhtml file I create a javascript object like

This ‘js\_obj’ is the javascript object which use all the time in this  
page to hide/show/change stuff depending on the users actions. At some  
point the user can click a button, which starts an AJAX  
request(button\_to\_function), which will update, lets say, tab 3. This  
means: I need to do the AJAX call and afterwards chnage to tab 3. I  
hoped that I could access to ‘js\_obj’ in my .rjs file so I could do  
something like

page.js\_obj.showTabByIndex(3)

This should change to tab 3, but doesn’t work. Hopefully I have the  
syntax wrong, do I ?

If this is not possible is there a way I can perform an action after the  
ajax request is finished with a button\_to\_function request ?

Thx  
LuCa

---

<div class="post-metadata">

**Author:** ![luca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/51bf81/32.png) [@luca](https://www.ruby-forum.com/u/luca)\
**Post date:** [April 9, 2007, 5:55pm UTC](https://www.ruby-forum.com/t/is-a-javascript-object-accessible-in-the-rjs-file-ajax/91477/2 "2007-04-09T17:55:10Z")

</div>

i may be wrong, but i think i read a couple of times that you can do  
this in an rjs file:

page \<\< “js\_obj.showTabByIndex(3)”

i think you can “feed” any JavaScript code into the page object like  
this, and it wll be sent back to the browser.  
could be wrong though, give it a try.

---

<div class="post-metadata">

**Author:** ![luca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/51bf81/32.png) [@luca](https://www.ruby-forum.com/u/luca)\
**Post date:** [April 9, 2007, 6:21pm UTC](https://www.ruby-forum.com/t/is-a-javascript-object-accessible-in-the-rjs-file-ajax/91477/3 "2007-04-09T18:21:46Z")

</div>

that works perfect, thnx

Just for those interested, I noticed that the same thing can also be  
done using

```
:complte => "js_obj.show......."

```

inside the button\_to\_function call (this is on the client side)

LuCa
