select_tag - observe field

68 views
Skip to first unread message

Jimmy Palmer

unread,
Mar 26, 2008, 6:03:35 PM3/26/08
to rubyonra...@googlegroups.com
I'm trying to do an ajax call when the select (drop down) gets changed.
What's the best way to do this?
--
Posted via http://www.ruby-forum.com/.

Mikel Lindsaar

unread,
Mar 26, 2008, 11:25:04 PM3/26/08
to rubyonra...@googlegroups.com
On Thu, Mar 27, 2008 at 9:03 AM, Jimmy Palmer
<rails-mai...@andreas-s.net> 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

John Lane

unread,
Apr 5, 2008, 11:06:48 AM4/5/08
to rubyonra...@googlegroups.com
Here's how to put an observer on a select box:

VIEW:
<%= select_tag :card_type, %{<option value="">Please Select...</option>}
+
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 :)

Reply all
Reply to author
Forward
0 new messages