# problems with calling javascript containing dynamic content in 	partial page

**URL:** <https://discuss.rubyonrails.org/t/problems-with-calling-javascript-containing-dynamic-content-in-partial-page/46931>\
**Category:** rubyonrails-talk\
**Created:** [October 19, 2009, 3:47pm UTC](https://discuss.rubyonrails.org/t/problems-with-calling-javascript-containing-dynamic-content-in-partial-page/46931 "2009-10-19T15:47:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lu\_Liu](https://avatars.discourse-cdn.com/v4/letter/l/e9bcb4/32.png) [@Lu\_Liu](https://discuss.rubyonrails.org/u/Lu_Liu)\
**Post date:** [October 19, 2009, 3:47pm UTC](https://discuss.rubyonrails.org/t/problems-with-calling-javascript-containing-dynamic-content-in-partial-page/46931/1 "2009-10-19T15:47:48Z")

</div>

Hi all,

I am trying to call some javascript function defined in partial page "\_results.html.erb". But it seemed that the js functions in the page are unrecognizable, and I have no idea why.

In my app, I have an "index" action/view containing an form\_remote\_tag sending the ajax request to a "process" action. After some calculation in the "process" action, it passes a local variable to a result page and renders it partially. Briefly, the index.html.erb looks like:

# index.html.erb \<% form\_remote\_tag :url =\> 'process', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:id =\> 'inputs', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:update =\> {:success =\> 'result\_div', :failure =\> 'document.write(request.responseText)'} do -%\> &nbsp;&nbsp;# some input tags here &nbsp;&nbsp;\<%= submit\_tag "calculate" %\> \<% end -%\> \<div id = 'result\_div'\>\</div\>

In controller#index, there is nothing. In controller#process, there is the calculation code which will cost several seconds, after that it is the render method:

def process &nbsp;&nbsp;# calculation code which will generate a result - @ruby\_result - which is an ruby object &nbsp;&nbsp;render :partial =\> 'results', :locals =\> {:ruby\_result =\> @ruby\_result} end

And in \_results.html.erb:

\<a href = "javascript:showResult()"\>show result\</a\> \<script type="text/javascript"\> &nbsp;&nbsp;function showResult() &nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// code to show the result somewhere else on the index page &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// BUT I MUST use the \<%=ruby\_result%\> variable here &nbsp;&nbsp;} \</script\>

The update of the result\_div is totally ok, but when I click on the "show result", nothing happened. I tried putting the showResult() function in the index.html.erb. Then it can be found by the \_results.html.erb. However the problem is that the ruby\_result can only be got after the process. As a result, it's not accessible in the index view when it is initially loaded. How should I solve this problem?

I am not sure if I have expressed my question clearly. Any reply or comment is welcome.

Thanks!
