Forum: Ruby on Rails RJS pain

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
5ef95bf95af5064ff3c2bcafa6a8a212?d=identicon&s=25 Dave M (Guest)
on 2007-03-08 15:15
(Received via mailing list)

I have a text field with the id 'list'

I am trying to add text to the field when a user clicks on a link with
this code

<%= link_to_function "#{}", update_page { |page|
          page[:list][:value] +=  "#{}"
                             } %>

but it fails.

a straight javascript function:

function addtext(text) {
         list = document.getElementById("list");
    list.value += text;

works so I am not sure what I am doing wrong.

Any ideas?

8bc543795b502900b5333aea73ad5533?d=identicon&s=25 Eden Li (edenli)
on 2007-03-08 15:41
(Received via mailing list)
er, you can't really express "+=" using the javascriptgenerator.

You'll need to dip into real javascript here:

<%= link_to_function || "", "$('list').value +=
'#{escape_javascript(}'" %>
5ef95bf95af5064ff3c2bcafa6a8a212?d=identicon&s=25 Dave M (Guest)
on 2007-03-08 18:12
(Received via mailing list)
Thanks for that, you really helped me out.

I Just started looking at rails so the  ' || ""', and the
escape_javascript( were also very helpful.

This topic is locked and can not be replied to.