# Evaluate javascript in Ajax.Request

**URL:** <https://www.ruby-forum.com/t/evaluate-javascript-in-ajax-request/129886>\
**Category:** Rails\
**Created:** [February 22, 2008, 12:25pm UTC](https://www.ruby-forum.com/t/evaluate-javascript-in-ajax-request/129886 "2008-02-22T12:25:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![frankiefoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/97f17d/32.png) [@frankiefoo](https://www.ruby-forum.com/u/frankiefoo)\
**Post date:** [February 22, 2008, 12:25pm UTC](https://www.ruby-forum.com/t/evaluate-javascript-in-ajax-request/129886/1 "2008-02-22T12:25:11Z")

</div>

Hi there,

does anyone know if it is possible to generate remote\_function calls in  
a dynamic fashion similar to this:

\<%= remote\_function(:url =\> {:action =\> “setComponent”, :component =\>  
comp, :value =\> document.getElementById("…").value})%\>

where I don’t want to evaulate the document.getElementById part but  
rather want to pass this javascript code to the Ajax.Request object for  
later evaluation.

The problem here is that the document.getElementById("…").value part  
is passed to the resulting Ajax.Request object as a string:

new  
Ajax.Request(’/epacs/setComponent?component=3&value=document.getElementById(…).value’,  
{asynchronous:true, evalScripts:true})

and seems to be never evaluated but rather passed to the server as a  
string.

How do I create this remote\_function call so that the javascript is  
evaluated at the very same time that the Ajax.Request is fired?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![frankiefoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/97f17d/32.png) [@frankiefoo](https://www.ruby-forum.com/u/frankiefoo)\
**Post date:** [February 22, 2008, 12:40pm UTC](https://www.ruby-forum.com/t/evaluate-javascript-in-ajax-request/129886/2 "2008-02-22T12:40:51Z")

</div>

On 22 Feb 2008, at 11:25, Frank P. wrote:

> where I don’t want to evaulate the document.getElementById part but  
> {asynchronous:true, evalScripts:true})
> 
> and seems to be never evaluated but rather passed to the server as a  
> string.

You need to use the :with option (ie remote\_function :url =\>  
{…}, :with =\> …)

Fred.
