# RJS Form Values

**URL:** <https://www.ruby-forum.com/t/rjs-form-values/96234>\
**Category:** Rails\
**Created:** [June 27, 2006, 4:03pm UTC](https://www.ruby-forum.com/t/rjs-form-values/96234 "2006-06-27T16:03:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hamza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a88e57/32.png) [@hamza](https://www.ruby-forum.com/u/hamza)\
**Post date:** [June 27, 2006, 4:03pm UTC](https://www.ruby-forum.com/t/rjs-form-values/96234/1 "2006-06-27T16:03:58Z")

</div>

Hi,

I have the following code :

\<%=link\_to\_function(“ä¸­ | China”, update\_page{|page|  
page[‘tags\_en’].value = “China”  
page[‘tags\_ch’].value = “ä¸­” }) %\>

This updates two text fields with the China and ä¸­. However I want to  
append the values, not replace them. So I need something like this :

\<%=link\_to\_function(“ä¸­ | China”, update\_page{|page|  
page[‘tags\_en’].value = page[‘tags\_en’].value + " China"  
page[‘tags\_ch’].value = page[‘tags\_ch’].value + " ä¸­" }) %\>

But that does not work. I am sure I can use the \<\< operator and do it  
via Javascript. But is there a better way ?

Thanks.  
Hamza

---

<div class="post-metadata">

**Author:** ![hamza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a88e57/32.png) [@hamza](https://www.ruby-forum.com/u/hamza)\
**Post date:** [June 27, 2006, 4:27pm UTC](https://www.ruby-forum.com/t/rjs-form-values/96234/2 "2006-06-27T16:27:55Z")

</div>

page.insert\_html ‘tags\_en’, :bottom, “China”

The docs are at  
[http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html#M000431](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html#M000431)  
There are a number of positions that you can put html and any html  
(should  
be valid) is allowed.

---

<div class="post-metadata">

**Author:** ![hamza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a88e57/32.png) [@hamza](https://www.ruby-forum.com/u/hamza)\
**Post date:** [June 27, 2006, 5:00pm UTC](https://www.ruby-forum.com/t/rjs-form-values/96234/3 "2006-06-27T17:00:36Z")

</div>

Hi,

That does not work. I didn’t think it would because the value it is  
updating is a Form text field () That is why I was using .value

Any other ideas anyone ?

Hamza

Daniel ----- wrote:

> page.insert\_html ‘tags\_en’, :bottom, “China”
> 
> The docs are at  
> [http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html#M000431](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html#M000431)  
> There are a number of positions that you can put html and any html  
> (should  
> be valid) is allowed.

---

<div class="post-metadata">

**Author:** ![hamza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a88e57/32.png) [@hamza](https://www.ruby-forum.com/u/hamza)\
**Post date:** [June 27, 2006, 5:40pm UTC](https://www.ruby-forum.com/t/rjs-form-values/96234/4 "2006-06-27T17:40:21Z")

</div>

Hamza,

You have to write a bit of JavaScript. The good news is that you can  
then use an RJS helper to hide it:

\<%=link\_to\_function(“e$BCfe(B | China”, update\_page{|page|  
page.append\_to “tags\_en”, " China"  
page.append\_to “tags\_ch”, " e$BCfe(B"}) %\>

Then define a method in your helper:

def append\_to(field, value)  
page \<\< “$(‘#{field}’).value = $F(‘#{field}’) + ‘#{value}’”  
end

On 6/27/06, Hamza Khan-Cheema [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Daniel ----- wrote:  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Cody F.  
[http://www.codyfauser.com](http://www.codyfauser.com)  
[RJS Templates for Rails [Book]](http://www.oreilly.com/catalog/rjsrails) (RJS Templates for Rails)

---

<div class="post-metadata">

**Author:** ![hamza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a88e57/32.png) [@hamza](https://www.ruby-forum.com/u/hamza)\
**Post date:** [June 27, 2006, 6:05pm UTC](https://www.ruby-forum.com/t/rjs-form-values/96234/5 "2006-06-27T18:05:14Z")

</div>

Thanks Cody, it works like a treat!

Kind Regards  
Hamza

Cody F. wrote:

> Hamza,
> 
> You have to write a bit of JavaScript. The good news is that you can  
> then use an RJS helper to hide it:
> 
> \<%=link\_to\_function(“e$BCfe(B | China”, update\_page{|page|  
> page.append\_to “tags\_en”, " China"  
> page.append\_to “tags\_ch”, " e$BCfe(B"}) %\>
> 
> Then define a method in your helper:
> 
> def append\_to(field, value)  
> page \<\< “$(‘#{field}’).value = $F(‘#{field}’) + ‘#{value}’”  
> end
> 
> On 6/27/06, Hamza Khan-Cheema [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Daniel ----- wrote:  
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > * * *
> > 
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> –  
> Cody F.  
> [http://www.codyfauser.com](http://www.codyfauser.com)  
> [RJS Templates for Rails [Book]](http://www.oreilly.com/catalog/rjsrails) (RJS Templates for Rails)
