# Rjs woes

**URL:** <https://www.ruby-forum.com/t/rjs-woes/81832>\
**Category:** Rails\
**Created:** [March 14, 2006, 8:01pm UTC](https://www.ruby-forum.com/t/rjs-woes/81832 "2006-03-14T20:01:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 14, 2006, 8:01pm UTC](https://www.ruby-forum.com/t/rjs-woes/81832/1 "2006-03-14T20:01:51Z")

</div>

i’ve just installed the RJS plugin per cody’s instructiuons and read  
through  
tutorials. I’ve made the necessary changes to my existing code and  
everything appears to be working, except that the returned javascript is  
not  
being evaluated…

here’s my setup:

i have a checkbox with an onclick event pointing to a javascript  
function.  
this javascript function does a few things then sends a request. I have  
the  
onSuccess callback pointing to another function who’s only purpose is to  
eval(resp.responseText). but this is not happening. i added an alert(  
resp.responseText) and the javascript code is there, it’s just not being  
evaluated.

checkbox:

 onclick="activate\_user(this)"/\>

javascript:

function activate\_user(cb) {  
var status = (cb.checked) ? “1” : “0”  
var data = “id” + cb.value + “&af=” + status  
var myReq = new Ajax.Request( ‘/admin/users/activate’, { :method:  
‘post’,  
parameters: data, onSuccess: success\_handler, …)  
}

function success\_handler(resp) {  
alert(resp.responseText);  
eval(resp.responseText);  
}

rjs template:

page.visual\_effect :highlight, “cb\_div”, { :start\_color =\> “#aaffaa” }

the success\_handler is getting called, as the alert shows the javascript  
being returned as:

new Effect.Hilight(‘cb\_div’, {startcolor:#aaffaa});

but as i said, it’s not getting evaluated in the eval() call. (i’m not  
seeing the effect)

anyone have any ideas?

Chris

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 15, 2006, 7:06am UTC](https://www.ruby-forum.com/t/rjs-woes/81832/2 "2006-03-15T07:06:13Z")

</div>

Chris,

There are a few problems here.

> page.visual\_effect :highlight, “cb\_div”, { :start\_color =\> “#aaffaa” }

The option is actually :startcolor and it looks like you’ll need extra  
quotes on the hex value, like “‘#aaffaa’” because the  
scriptaculous\_helper doesn’t correctly place the :startcolor option  
within quotes.

> the success\_handler is getting called, as the alert shows the javascript  
> being returned as:
> 
> new Effect.Hilight(‘cb\_div’, {startcolor:#aaffaa});  
> Is this a typo or did you incorrectly spell Highlight here?

With the double quoting this will become:  
new Effect.Highlight(‘cb\_div’, {startcolor:‘#aaffaa’});

I tried this out in a quick test and without the extra quotes the  
effect wasn’t applied. I got a nice green highlight with the extra  
quotes.

> but as i said, it’s not getting evaluated in the eval() call. (i’m not  
> seeing the effect)

You shouldn’t actually have to eval this yourself. Prototype will  
eval the response automatically because RJS sets the Content-Type  
header to text/javascript.

Hope this helps.

> 

–  
Cody F.  
[http://www.codyfauser.com](http://www.codyfauser.com)

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 15, 2006, 2:45pm UTC](https://www.ruby-forum.com/t/rjs-woes/81832/3 "2006-03-15T14:45:33Z")

</div>

Cody,

thanks so much for the assist. the missing quotes was the issue.

and thanks for the plugin!

Chris
