RJS Form Values

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

page.insert_html ‘tags_en’, :bottom, “China”

The docs are at
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.

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
There are a number of positions that you can put html and any html
(should
be valid) is allowed.

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 [email protected] wrote:

Daniel ----- wrote:
Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


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

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 [email protected] wrote:

Daniel ----- wrote:
Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs