# remote\_function with local javascript variable

**URL:** <https://discuss.rubyonrails.org/t/remote-function-with-local-javascript-variable/2326>\
**Category:** rubyonrails-talk\
**Created:** [September 28, 2006, 11:46pm UTC](https://discuss.rubyonrails.org/t/remote-function-with-local-javascript-variable/2326 "2006-09-28T23:46:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dang](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@dang](https://discuss.rubyonrails.org/u/dang)\
**Post date:** [September 28, 2006, 11:46pm UTC](https://discuss.rubyonrails.org/t/remote-function-with-local-javascript-variable/2326/1 "2006-09-28T23:46:28Z")

</div>

Hi list,

I'm trying to get a local javascript variable submitted with remote\_function:

\<script language="javascript"\>

var local\_variable = "I do really important stuff"; \<%= remote\_function :url =\> {:action =\> "boo", :id=\> 1}, :submit =\> 'local\_variable' %\>

\</script\>

The above snippet seems to be close but generates new Ajax.Updater('foo', '/temp/boo/1', {asynchronous:true, evalScripts:true, parameters:Form.serialize('local\_variable')})

but I don't want the form to be serialized (there is no form!) I want the value of 'local\_variable' to be serialized and submitted. Any ideas?

Thanks, Dan

---

<div class="post-metadata">

**Author:** ![Vishnu\_Gopal](https://avatars.discourse-cdn.com/v4/letter/v/b9e5f3/32.png) [@Vishnu\_Gopal](https://discuss.rubyonrails.org/u/Vishnu_Gopal)\
**Post date:** [September 29, 2006, 6:48am UTC](https://discuss.rubyonrails.org/t/remote-function-with-local-javascript-variable/2326/2 "2006-09-29T06:48:14Z")

</div>

Maybe remote\_function [http://rubyonrails.org/api/classes/ActionView/Helpers/PrototypeHelper.html#M000420](http://rubyonrails.org/api/classes/ActionView/Helpers/PrototypeHelper.html#M000420) with a :with parameter will help?

Vish

---

<div class="post-metadata">

**Author:** ![dang](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@dang](https://discuss.rubyonrails.org/u/dang)\
**Post date:** [September 29, 2006, 7:59am UTC](https://discuss.rubyonrails.org/t/remote-function-with-local-javascript-variable/2326/3 "2006-09-29T07:59:46Z")

</div>

thanks - looks like this might do the trick:

remote\_function :url =\> {:action =\> "boo", :id=\> 1}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:with =\> "'variable='+local\_variable"

It looks like this appends &variable=blah to the URL which is enough for me, but it would be interesting to see if it could serialise and post variable values as well - maybe some other time!
