RJS pain

Hi,

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 “#{item.name}”, update_page { |page|
page[:list][:value] += “#{item.name}”
} %>

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?

David.

er, you can’t really express “+=” using the javascriptgenerator.

You’ll need to dip into real javascript here:

<%= link_to_function item.name || “”, “$(‘list’).value +=
‘#{escape_javascript(item.name)}’” %>

Thanks for that, you really helped me out.

I Just started looking at rails so the ‘item.name || “”’, and the
escape_javascript(item.name) were also very helpful.

David.