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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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)}''" %>
On Mar 8, 10:14 pm, "Dave M"
<moos...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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. On Mar 8, 2:37 pm, "eden li" <eden...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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)}''" %> > > On Mar 8, 10:14 pm, "Dave M" <moos...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---