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
--
Posted via http://www.ruby-forum.com/.
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. On 6/28/06, Hamza Khan-Cheema <hamzakc@gmail.com> wrote:> > 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060627/25303309/attachment-0001.html
Hi, That does not work. I didn''t think it would because the value it is updating is a Form text field (<input>) 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.-- Posted via http://www.ruby-forum.com/.
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("? | China", update_page{|page|
page.append_to "tags_en", " China"
page.append_to "tags_ch", " ?"}) %>
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 <hamzakc@gmail.com>
wrote:> Hi,
>
> That does not work. I didn''t think it would because the value it
is
> updating is a Form text field (<input>) 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.
>
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Cody Fauser
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 Fauser 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("$BCf(B | China", update_page{|page| > page.append_to "tags_en", " China" > page.append_to "tags_ch", " $BCf(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 <hamzakc@gmail.com> wrote: >> Daniel ----- wrote: >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > -- > Cody Fauser > http://www.codyfauser.com > http://www.oreilly.com/catalog/rjsrails (RJS Templates for Rails)-- Posted via http://www.ruby-forum.com/.