# RJS pain

**URL:** <https://www.ruby-forum.com/t/rjs-pain/88153>\
**Category:** Rails\
**Created:** [March 8, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/rjs-pain/88153 "2007-03-08T15:15:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 8, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/rjs-pain/88153/1 "2007-03-08T15:15:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 8, 2007, 3:41pm UTC](https://www.ruby-forum.com/t/rjs-pain/88153/2 "2007-03-08T15:41:10Z")

</div>

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)}’” %\>

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 8, 2007, 6:12pm UTC](https://www.ruby-forum.com/t/rjs-pain/88153/3 "2007-03-08T18:12:36Z")

</div>

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.
