# Appending to a textarea with RJS

**URL:** <https://www.ruby-forum.com/t/appending-to-a-textarea-with-rjs/118359>\
**Category:** Rails\
**Created:** [October 26, 2007, 3:00am UTC](https://www.ruby-forum.com/t/appending-to-a-textarea-with-rjs/118359 "2007-10-26T03:00:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnhutch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@johnhutch](https://www.ruby-forum.com/u/johnhutch)\
**Post date:** [October 26, 2007, 3:00am UTC](https://www.ruby-forum.com/t/appending-to-a-textarea-with-rjs/118359/1 "2007-10-26T03:00:55Z")

</div>

Ok, this is driving me nuts. I’m trying to RJS some text into a  
text\_area which may or may not have been written in by the user. if I  
page.insert\_html :before, :after, :top, or :bottom, it either sticks  
the contents above or below the text box (but never in). If I do:

page[:textboxid].value = “blah”

it overwrites the contents of the textbox but doesn’t APPEND to it.  
I’ve tried doing something to the effect of

page[:textboxid].value = “blah” + page[:textboxid].value  
or  
page[:textboxid].value = “blah” + $#{‘textboxid’}.value

and several variants. But I keep getting errors. Or… nothing.  
Someone please help me before I put my fist through my screen.

---

<div class="post-metadata">

**Author:** ![johnhutch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@johnhutch](https://www.ruby-forum.com/u/johnhutch)\
**Post date:** [October 26, 2007, 3:40am UTC](https://www.ruby-forum.com/t/appending-to-a-textarea-with-rjs/118359/2 "2007-10-26T03:40:40Z")

</div>

Thats a good question. I can’t get it to work with RJS, but this simple  
prototype based javascript works fine. I guess you could stick it in a  
function and call your function from RJS.

$(‘tarea’).value = $(‘tarea’).getValue() + " blah"

johnhutch wrote:

> page[:textboxid].value = “blah” + page[:textboxid].value  
> or  
> page[:textboxid].value = “blah” + $#{‘textboxid’}.value
> 
> and several variants. But I keep getting errors. Or… nothing.  
> Someone please help me before I put my fist through my screen.
> 
> >

–  
Sincerely,

William P.

---

<div class="post-metadata">

**Author:** ![johnhutch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@johnhutch](https://www.ruby-forum.com/u/johnhutch)\
**Post date:** [October 26, 2007, 5:05am UTC](https://www.ruby-forum.com/t/appending-to-a-textarea-with-rjs/118359/3 "2007-10-26T05:05:58Z")

</div>

YAYYYY IT WORKED! Here’s my RJS/javascript code:

```
  <%= link_to_function "Append to Text Area" do |page|
    page << "$('textarea_id').value = $('textarea_id).getValue() +

```

‘blah!’"  
end  
%\>
