select with onChange

oozy wrote:

I'm trying to use a with a a simple javascript alert. This is my code.

<%=, 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.

just do:

<%= select('contact', 'city', [ 'Mumbai', 'Paris', 'London'], :onchange => :my_fun) %>

Suhas Nehete wrote: