# Pass a ruby value to javascript in form\_remote\_tag

**URL:** <https://www.ruby-forum.com/t/pass-a-ruby-value-to-javascript-in-form-remote-tag/113974>\
**Category:** Rails\
**Created:** [September 6, 2007, 7:59pm UTC](https://www.ruby-forum.com/t/pass-a-ruby-value-to-javascript-in-form-remote-tag/113974 "2007-09-06T19:59:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![deramoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b38774/32.png) [@deramoo](https://www.ruby-forum.com/u/deramoo)\
**Post date:** [September 6, 2007, 7:59pm UTC](https://www.ruby-forum.com/t/pass-a-ruby-value-to-javascript-in-form-remote-tag/113974/1 "2007-09-06T19:59:43Z")

</div>

hi, guys, I am trying to pass a ruby value to a javascript function  
which is called in “:complete” of a form\_remote\_tag, but everytime I  
submit the form, javascript can’t get the changed value.

Here is how I tried.

in rhtml file,  
\<%= form\_remote\_tag :url =\>{:action =\> ‘dosomething’},  
:complete =\> “func(#{@session[:var]});”%\>  
…  
…  
\<%= end\_form\_tag %\>

in rb file,

class MyController \< ApplicationController  
def dosomething  
# update var and put it into session  
…  
end  
end

Any hints on what’s wrong here?

And I tried the way Pratik mentioned  
here([Replace\_html + javascript - Rails - Ruby-Forum](http://www.ruby-forum.com/topic/73891#109323)) to regenerate the  
javascript,  
but it seems not working.

Advices will be appreciated.

---

<div class="post-metadata">

**Author:** ![deramoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b38774/32.png) [@deramoo](https://www.ruby-forum.com/u/deramoo)\
**Post date:** [September 7, 2007, 10:57am UTC](https://www.ruby-forum.com/t/pass-a-ruby-value-to-javascript-in-form-remote-tag/113974/2 "2007-09-07T10:57:19Z")

</div>

> ```
> :complete => "func(#{@session[:var]});"%>
> 
> ```

it’s the quotes i think  
try

> ```
> :complete => "func( '#{@session[:var]}' );"%>
> 
> ```

hope this helps,  
phil

On 6 Sep., 19:59, “Deramoo A.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![deramoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b38774/32.png) [@deramoo](https://www.ruby-forum.com/u/deramoo)\
**Post date:** [September 7, 2007, 3:02pm UTC](https://www.ruby-forum.com/t/pass-a-ruby-value-to-javascript-in-form-remote-tag/113974/3 "2007-09-07T15:02:06Z")

</div>

thank you, phil, I tried that way, but it didn’t work. The value  
remained to  
be the same as html first rendered.

deramoo

removed\_email\_address@domain.invalid wrote:

> > ```
> > :complete => "func(#{@session[:var]});"%>
> > 
> > ```
> 
> it’s the quotes i think  
> try
> 
> > ```
> > :complete => "func( '#{@session[:var]}' );"%>
> > 
> > ```
> 
> hope this helps,  
> phil
> 
> On 6 Sep., 19:59, “Deramoo A.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![deramoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b38774/32.png) [@deramoo](https://www.ruby-forum.com/u/deramoo)\
**Post date:** [September 7, 2007, 5:58pm UTC](https://www.ruby-forum.com/t/pass-a-ruby-value-to-javascript-in-form-remote-tag/113974/4 "2007-09-07T17:58:49Z")

</div>

Now I put the value into XMLHttpRequest, and pass  
the whole responseText of XMLHttpRequest to the javascript function.  
Thus I can parse the text and get the updated ruby value.  
It’s quite a lame solution, I think, but by now I have no other ways.

Deramoo A. wrote:

> thank you, phil, I tried that way, but it didn’t work. The value  
> remained to  
> be the same as html first rendered.
> 
> deramoo
