# Can Javascript code be called from with \<%= %\> tags

**URL:** <https://www.ruby-forum.com/t/can-javascript-code-be-called-from-with-tags/138955>\
**Category:** Rails\
**Created:** [May 29, 2008, 10:27am UTC](https://www.ruby-forum.com/t/can-javascript-code-be-called-from-with-tags/138955 "2008-05-29T10:27:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeffB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/0ea827/32.png) [@JeffB](https://www.ruby-forum.com/u/JeffB)\
**Post date:** [May 29, 2008, 10:27am UTC](https://www.ruby-forum.com/t/can-javascript-code-be-called-from-with-tags/138955/1 "2008-05-29T10:27:00Z")

</div>

I want to make a call to remote\_function with 1 of the parameters  
derived from a javascript call.

For example:  
\<%= remote\_function(:url =\> {:action = “xyz”, :id =\> getId()}, :update  
=\> ‘main\_content’) %\>

getId() is a Javascript function.

Can something like this be done?

Conversely,  
can the remote\_function(options) call be made from javascript.

Something like  
def f()  
{  
var options = {“url”: {“action”: “xyz”, “id” : getId()}, “update”:  
“main\_content”};  
remote\_function(options);  
}

---

<div class="post-metadata">

**Author:** ![JeffB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/0ea827/32.png) [@JeffB](https://www.ruby-forum.com/u/JeffB)\
**Post date:** [May 29, 2008, 10:39am UTC](https://www.ruby-forum.com/t/can-javascript-code-be-called-from-with-tags/138955/2 "2008-05-29T10:39:25Z")

</div>

On 28 May 2008, at 23:36, JeffB wrote:

> Can something like this be done?

Yes and no. The javascript clearly cannot be evaluated at the time  
that the \<%= is evaluated, since that happens server side.  
However, the remote\_function family do take a :with option, which is a  
string of javascript to be executed and bashed into the parameters  
when the ajax call is made. I wrote up some of the ways of playing  
with the :with option at

> **[:with or :without you: link\_to\_remote's mysterious parameter - Space Vatican](https://www.spacevatican.org/2008/5/17/with-or-without-you-link_to_remote-s-mysterious-parameter/)**
>
> One of the nice things about Rails is that it makes it really easy to get off the ground with Ajax, thanks to the link\_to\_remote helper (and all the …

> Conversely,  
> can the remote\_function(options) call be made from javascript.

remote\_function just generates some javascript, usually something like

new Ajax.Updater(‘some\_div’, /foo/bar, {some: options}

Fred
