How update a select onchange?

Hey all,
I have a select(“post”, “person_id”, Person.find_all.collect {|p|
[ p.name, p.id ] }) and I would like to submit the value when it is
selected.
I know I have to do something like this: onchange="<%=
remote_function(:update => “options”,
:url => { :action => :update_options })
but how can I pass it the value of the selected option?

thanx in advance

Pat

remote_function(:update => “options”,
:url => { :action => :update_options },
:with => “‘post%5Bperson_id%5D=’+$F(‘post_person_id’)”)

HTH,
Pratik

On 11/19/06, Patrick A. [email protected] wrote:

thanx in advance

Pat


rm -rf / 2>/dev/null - http://null.in

Dont judge those who try and fail, judge those who fail to try…

On 11/20/06, Pratik [email protected] wrote:

remote_function(:update => “options”,
:url => { :action => :update_options },
:with => “‘post%5Bperson_id%5D=’+$F(‘post_person_id’)”)

Hey Pratik, thanx for your anwser,
basically, this is what I have:

No<option value=“1”

YesNo<option value=“3”
Maybe

the poblem is that the updated value of confvalue is
‘this[this.selectedIndex].value’ instead of the selected value.
I also tried something like that:

:with=>config[confvalue]‘=>’+this[this.selectedIndex].value’

but in that case nothing get updated at all.
any idea what’s wrong?

thanx in advance

Pat

On 11/20/06, Patrick A. [email protected] wrote:

‘this[this.selectedIndex].value’ instead of the selected value.
Pat

Pat,

You can also use observe_field().

<%= select :post, :person_id, Person.find(:all).collect {|p| [ p.name,
p.id ] } %>
<%= observe_field :post_person_id, :url => { … }, :with =>
‘post_person_id’ %>

Hope this helps,


Zack C.
http://depixelate.com
http://trackplace.com

Patrick,

Here is a select that will be submitted via AJAX request when changed:

<%= select( :vehicle, :body_type,
@body_types.collect {|bt| [bt, bt]},
{},
:onchange => remote_function( :with =>
“‘vehicle[body_type]=’+escape(value)”,
:loading =>
“Element.show(‘loading-indicator4’)”,
:complete =>
evaluate_remote_response,
:url => { :action =>
:vehicle_body_type_select } ) ) %>

This will run the method ‘vehicle_body_type_select’ in the current
controller, and when that action is executed the currently selected
value will be in ‘params[:vehicle][:body_type]’ from the :with
parameter. The method passes back Javascript via RJS statements which
are evaluated by the :complete item.

David