I am just learning Ruby.
I created a simple application where an record is added from a "new"
view. Some input fields are defined as a select option (using a
helper). Now I want to add a Javascript function with "onclick"
function. How can I do it?
Helper:
module MypagesHelper
def my_pictures
pictures = [ ''pic1'', ''pic2'',
''pic3'',
''pic4'',''pic5'',''pic6'' ]
pictures_list = pictures.sort
pictures_list.collect{|l| l}
end
end
View:
<% form_for(@mypage) do |f| %>
<%= f.error_messages %>
<%= f.label :backgroud_picture %><br />
<%= f.select :backgroud_picture, my_pictures %>
Thanks,
Zalek
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On 3 October 2010 02:09, zalek <zalekbloom-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> I want to add a Javascript function with "onclick" > function. How can I do it? > > <%= f.select :backgroud_picture, my_pictures %>You probably don''t want onClick; onChange is more likely to be more usable with a select box, but either way, just add it to the f.select (here''s an example I''ve used with a select_tag, but the principle''s the same) : <%= select_tag("note[notes]", options_for_select([["quick note", ""], ["no answer", "Called, no answer"], ["no show", "Appointment no show"]]), :onchange => "if(this.value != '''' && confirm(''Create quick note?'')){this.form.submit()}") %> -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling wrote:> You probably don''t want onClick; onChange is more likely to be more > usable with a select box, but either way, just add it to the f.select > (here''s an example I''ve used with a select_tag, but the principle''s > the same) : > > <%= select_tag("note[notes]", options_for_select([["quick note", > ""], ["no answer", "Called, no answer"], ["no show", "Appointment no > show"]]), :onchange => "if(this.value != '''' && confirm(''Create quick > note?'')){this.form.submit()}") %>The onClick event is inconsistent between browsers when used on a select tag. However, that being said, it''s time to start using Unobtrusive JavaScript (UJS) techniques. It''s the way Rails 3 does it, and it''s time for us all to start doing it. http://en.wikipedia.org/wiki/Unobtrusive_JavaScript -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.