# Get back a Javascript variable

**URL:** <https://www.ruby-forum.com/t/get-back-a-javascript-variable/103551>\
**Category:** Rails\
**Created:** [May 7, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/get-back-a-javascript-variable/103551 "2007-05-07T20:51:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![guillaume](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c67d28/32.png) [@guillaume](https://www.ruby-forum.com/u/guillaume)\
**Post date:** [May 7, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/get-back-a-javascript-variable/103551/1 "2007-05-07T20:51:05Z")

</div>

Hi,

I ve performed some search but i don t really find what i want to do…  
So it s simple, i need to get back in a controller or a view a  
Javascript variable (which i use to detect the version of a flash  
player)…

How can i dot that ?

thank you for helping

Guillaume.

---

<div class="post-metadata">

**Author:** ![guillaume](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c67d28/32.png) [@guillaume](https://www.ruby-forum.com/u/guillaume)\
**Post date:** [May 7, 2007, 8:59pm UTC](https://www.ruby-forum.com/t/get-back-a-javascript-variable/103551/2 "2007-05-07T20:59:54Z")

</div>

Hi,

Do this by making this call in the section of your .rhtml page.  
\<%= javascript\_include\_tag “Name Of Javascript” %\>

I thik this will resolve your problem.

Julio

On 5/7/07, Guillaume [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> thank you for helping
> 
> Guillaume.
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
abracos,

Julio Cesar

---

<div class="post-metadata">

**Author:** ![guillaume](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c67d28/32.png) [@guillaume](https://www.ruby-forum.com/u/guillaume)\
**Post date:** [May 7, 2007, 10:36pm UTC](https://www.ruby-forum.com/t/get-back-a-javascript-variable/103551/3 "2007-05-07T22:36:11Z")

</div>

Thanks for your help,  
but i already included that… my problem is to return the Javascript  
variable in a ruby variable…

Cause Javascript is executed on Client side, so i don t see how to get  
back the content of that variable later in the ruby code

I hope to be clear…

thanks

Julio Cesar wrote:

> Hi,
> 
> Do this by making this call in the section of your .rhtml page.  
> \<%= javascript\_include\_tag “Name Of Javascript” %\>
> 
> I thik this will resolve your problem.
> 
> Julio
> 
> On 5/7/07, Guillaume [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > thank you for helping
> > 
> > Guillaume.
> > 
> > –  
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > >
> 
> –  
> abracos,
> 
> Julio Cesar

---

<div class="post-metadata">

**Author:** ![guillaume](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c67d28/32.png) [@guillaume](https://www.ruby-forum.com/u/guillaume)\
**Post date:** [May 7, 2007, 10:46pm UTC](https://www.ruby-forum.com/t/get-back-a-javascript-variable/103551/4 "2007-05-07T22:46:28Z")

</div>

Maybe you should include some more context regarding your problem.  
There are many ways to send client information to the server…you  
could send this along as part of a form POST, or in the query part of a  
URL, or using XMLHttpRequest, or…

Guillaume wrote:

> Thanks for your help,  
> but i already included that… my problem is to return the Javascript  
> variable in a ruby variable…
> 
> Cause Javascript is executed on Client side, so i don t see how to get  
> back the content of that variable later in the ruby code
> 
> I hope to be clear…
> 
> thanks

---

<div class="post-metadata">

**Author:** ![guillaume](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c67d28/32.png) [@guillaume](https://www.ruby-forum.com/u/guillaume)\
**Post date:** [May 7, 2007, 10:44pm UTC](https://www.ruby-forum.com/t/get-back-a-javascript-variable/103551/5 "2007-05-07T22:44:05Z")

</div>

On May 7, 2007, at 10:36 PM, Guillaume wrote:

> Thanks for your help,  
> but i already included that… my problem is to return the Javascript  
> variable in a ruby variable…
> 
> Cause Javascript is executed on Client side, so i don t see how to get  
> back the content of that variable later in the ruby code

You have to send it back somehow. A hidden field in a form, a  
parameter in the URL, Ajax, …

You’ll typically write JavaScript code to hook into the new request  
to add the value of the variable when the request starts. For  
instance, if there’s a form some code in onsubmit sets the hidden  
field to the value of the variable at that moment. You see the idea.

– fxn

---

<div class="post-metadata">

**Author:** ![guillaume](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c67d28/32.png) [@guillaume](https://www.ruby-forum.com/u/guillaume)\
**Post date:** [May 8, 2007, 12:03am UTC](https://www.ruby-forum.com/t/get-back-a-javascript-variable/103551/6 "2007-05-08T00:03:07Z")

</div>

So there it is…

I ve got some javascript in a view (a part of the view code)… this  
javascript has a variable TOTO…  
At the end of the javascript execution in the view, this variable TOTO  
contain information that i need later…

So to use this information later, i need to put the content of the  
Javascript variable TOTO in a new ruby variable…

how do you do that ?

thanks again

Guest wrote:

> Maybe you should include some more context regarding your problem.  
> There are many ways to send client information to the server…you  
> could send this along as part of a form POST, or in the query part of a  
> URL, or using XMLHttpRequest, or…
> 
> Guillaume wrote:
> 
> > Thanks for your help,  
> > but i already included that… my problem is to return the Javascript  
> > variable in a ruby variable…
> > 
> > Cause Javascript is executed on Client side, so i don t see how to get  
> > back the content of that variable later in the ruby code
> > 
> > I hope to be clear…
> > 
> > thanks

---

<div class="post-metadata">

**Author:** ![guillaume](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c67d28/32.png) [@guillaume](https://www.ruby-forum.com/u/guillaume)\
**Post date:** [May 8, 2007, 6:49pm UTC](https://www.ruby-forum.com/t/get-back-a-javascript-variable/103551/7 "2007-05-08T18:49:15Z")

</div>

I think what other people have already said. Put your variable inside a  
hidden text field or someplace else in the dom and then read it out of  
it  
with an AJAX call. There’s multiple possibilities for getting the value  
with something like that.

On 5/8/07, Guillaume [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > I ve got some javascript in a view (a part of the view code)… this
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Terry (TAD) Donaghe  
[http://tadspot.tumblr.com](http://tadspot.tumblr.com)

---

<div class="post-metadata">

**Author:** ![guillaume](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c67d28/32.png) [@guillaume](https://www.ruby-forum.com/u/guillaume)\
**Post date:** [May 8, 2007, 7:15pm UTC](https://www.ruby-forum.com/t/get-back-a-javascript-variable/103551/8 "2007-05-08T19:15:53Z")

</div>

You said multiple possibilty… could you give me a bit of more details,  
so i will google it… i me quiet a newb on RoR, so…

Thank you…

Terry D. wrote:

> I think what other people have already said. Put your variable inside a  
> hidden text field or someplace else in the dom and then read it out of  
> it  
> with an AJAX call. There’s multiple possibilities for getting the value  
> with something like that.
> 
> On 5/8/07, Guillaume [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > > I ve got some javascript in a view (a part of the view code)… this
> > 
> > –  
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > >
> 
> –  
> Terry (TAD) Donaghe  
> [http://tadspot.tumblr.com](http://tadspot.tumblr.com)

---

<div class="post-metadata">

**Author:** ![guillaume](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c67d28/32.png) [@guillaume](https://www.ruby-forum.com/u/guillaume)\
**Post date:** [May 8, 2007, 6:39pm UTC](https://www.ruby-forum.com/t/get-back-a-javascript-variable/103551/9 "2007-05-08T18:39:54Z")

</div>

any idea ?

thank you…

Guillaume wrote:

> So there it is…
> 
> I ve got some javascript in a view (a part of the view code)… this  
> javascript has a variable TOTO…  
> At the end of the javascript execution in the view, this variable TOTO  
> contain information that i need later…
> 
> So to use this information later, i need to put the content of the  
> Javascript variable TOTO in a new ruby variable…
> 
> how do you do that ?
> 
> thanks again
