RJS Dynamic Javascript update on page

Using RJS is it possible to update the javascript code within the

"

But on subsequent access the var still has value “hello”.
Any suggestion on this will be highly appreciated.

Thanks

Nasir K. wrote:

Using RJS is it possible to update the javascript code within the

tag in the ? So what I have done is that I have the wrapped in a
. On a certain action I use RJS to update that
using page.replace_html. The logs show that the
actually gets replaced, but the new javascript does not take effect. The div -
var = "hello";

RJS should not replace the javascript in a div to be executed, because
RJS is javascript being executed in the first place. Simply execute
your javascript in your RJS template and leave writing script tags to
the DOM out of it completely.

When responding to AJAX calls with HTML and not javascript, it will by
default look for tags and execute them. The same is not true
if the response is javascript since it is already execute a script and
wont scan the DOM for script tags again.

rjs_example.rjs

page[‘something’].visual_effect :highlight
page << ‘var = “hello”;’

Writing a script tag with javascript is just silly if you want it to
execute immediately. Remember that RJS will execute on the page it’s
called from, even though it’s a new request since the javascript it
generates doesn’t execute until it’s arrived on the page that requested
it.