Hi, I''m trying to use a form.select with a a simple javascript alert. This is my code. <%= form.select(:entry_type, Entry::TYPES, :prompt => "Select The Type", :onChange => "alert(''test'')") %> The form loads without any issue, but onChange is not in the HTML source. Of course, since the onChange is not in the source, nothing happens regardless of the list item I select. Does anybody know what is going on? Why is the onChange not appearing in the source? Thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
the format for the select helper is the following: select(object, method, choices, options = {}, html_options = {}) so you should use something like: <%= select(object, method, choices, { :prompt => "Select the Type"}, { :onchange => "alert(''test'');"}) %> Adam On 7/5/07, oozy <oozyval-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > I''m trying to use a form.select with a a simple javascript alert. > This is my code. > <%= form.select(:entry_type, Entry::TYPES, :prompt => "Select The > Type", :onChange => "alert(''test'')") %> > > The form loads without any issue, but onChange is not in the HTML > source. Of course, since the onChange is not in the source, nothing > happens regardless of the list item I select. > > Does anybody know what is going on? Why is the onChange not appearing > in the source? > > Thanks > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
oozy wrote:> I''m trying to use a form.select with a a simple javascript alert. > This is my code.> <%= form.select(:entry_type, Entry::TYPES, :prompt => "Select The > Type", :onChange => "alert(''test'')") %>Here''s a working onChange under a different Rails function: <% select( :user, :fighter_image_url, images, { :selected => current_user.fighter_image_url }, { :onchange => ''$("fighter_image_reflector").src = "/images/fighters/"+this.value;'' } ) %> One of the major joys and challenges of Rails is how many different ways it supports to pass raw HTML attributes into methods that generate HTML. It''s a credit to Ruby''s infinite flexibility that Rails can support so many. For example, the above method doesn''t take just one trailing hash. (A trailing hash is how most :foo => :bar magic works, without {}). In this case, Rails takes some fixed arguments, then takes two hashes, one for dynamic options and the other for raw HTML arguments. Research the prototype to your select, and determine which argmument gets the :onchange. -- Phlip http://www.oreilly.com/catalog/9780596510657/ "Test Driven Ajax (on Rails)" assert_xpath, assert_javascript, & assert_ajax --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
how to use :onchange with select box in following case ? <%= select(''contact'', ''city'', [ ''Mumbai'', ''Paris'', ''London''], { :onchange => "my_fun();" }) %> here ''my_fun()'' is my javascript function. Any help ? -- Thanks, SN. -- 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-/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 -~----------~----~----~----~------~----~------~--~---
just do: <%= select(''contact'', ''city'', [ ''Mumbai'', ''Paris'', ''London''], :onchange => :my_fun) %> Suhas Nehete wrote:> how to use :onchange with select box in following case ? > > <%= select(''contact'', ''city'', [ ''Mumbai'', ''Paris'', ''London''], { > :onchange => "my_fun();" }) %> > > here ''my_fun()'' is my javascript function. > > > Any help ? > > > -- > Thanks, > SN. >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---