Select_tag - observe field

I’m trying to do an ajax call when the select (drop down) gets changed.
What’s the best way to do this?

On Thu, Mar 27, 2008 at 9:03 AM, Jimmy P.
[email protected] wrote:

I’m trying to do an ajax call when the select (drop down) gets changed.
What’s the best way to do this?

I wrote up something similar here:

http://lindsaar.net/2008/2/25/javascript-field-monitor

This is a javascript file that monitors every input and select on a
form and highlights it if it changes.

You can replace the highlight code with an AJAX call if you want.

Regards

Mikel

Here’s how to put an observer on a select box:

VIEW:
<%= select_tag :card_type, %{Please Select…}
+
options_for_select(supported_card_types) %>

<%= observe_field :card_type,
:frequency => 0.5,
:url => {:action => :display_card_fields, :only_path
=> :false},
:with => “‘card_type=’+encodeURIComponent(value)” %>

This calls RJS file “display_card_fields.js.rjs” when the select box
changes, sending the value card_type in the params hash.

Hope this helps you :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs