XMLHttpRequest on select index change

Hi

I want to trigger a XMLHttpRequest when the selected index change of a
drop down box. What’s the best way to handle this?

I’m sure I could figure out what javascript call link_to_remote is
making and just wire that up to the drop down box, but I’m just
wondering if there is a preferred or built in rails way to do this. Is
there?

Thanks,
Brandon

On 18 Oct 2007, at 17:50, Brandon C. wrote:

Hi

I want to trigger a XMLHttpRequest when the selected index change of a
drop down box. What’s the best way to handle this?

I’m sure I could figure out what javascript call link_to_remote is
making and just wire that up to the drop down box, but I’m just
You don’t need to: remote_function will do that for you. The
documentation for it even use a drop down box as its example.
Fred

Frederick

Thanks for point out remote_function. I’ll go read about it.

I just tried it out, very cool, but not what I need. I need the drop
down ochange to post the whole form, and then I need to stick the
results into an html element inside the form.

I think I can figure it though.

Ok…I got it. I’m not sure if this is the right way, but it works. I
added this to the remote_function options

:with => “Form.serialize($(‘tune_in_form_#{c.id}’))”

Ok…I can better explain the problem now

remote_function is generating an AJAX.Update like this:

new Ajax.Updater(‘tune_in_link_1’,
‘/my_account/tune_in/update_tune_in_link?channel_id=1’,
{asynchronous:true, evalScripts:true, parameters:Form.serialize(this)})

I need an Ajax.Updater like this:

new Ajax.Updater(‘tune_in_link_1’,
‘/my_account/tune_in/update_tune_in_link?channel_id=1’,
{asynchronous:true, evalScripts:true,
parameters:Form.serialize(this.form)})

Note the difference in parameters:Form.serialize. It has to be
this.form, not this. this evaluates to a select box, this.form evaluates
to the form that select box lives on, and I need that is what I need
serialized.

Is this something I have control over with the ajax helpers, or am I
supposed to build the javascript myself?

Thanks.

On 19 Oct 2007, at 00:19, Brandon C. wrote:

Ok…I got it. I’m not sure if this is the right way, but it works. I
added this to the remote_function options

:with => “Form.serialize($(‘tune_in_form_#{c.id}’))”

I think that the :submit parameter can be used for this in a
slightly more elegant way.

Fred

Thanks. That is more elegant.