# XMLHttpRequest on select index change

**URL:** <https://www.ruby-forum.com/t/xmlhttprequest-on-select-index-change/117625>\
**Category:** Rails\
**Created:** [October 18, 2007, 6:50pm UTC](https://www.ruby-forum.com/t/xmlhttprequest-on-select-index-change/117625 "2007-10-18T18:50:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![metrix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@metrix](https://www.ruby-forum.com/u/metrix)\
**Post date:** [October 18, 2007, 6:50pm UTC](https://www.ruby-forum.com/t/xmlhttprequest-on-select-index-change/117625/1 "2007-10-18T18:50:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![metrix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@metrix](https://www.ruby-forum.com/u/metrix)\
**Post date:** [October 18, 2007, 7:04pm UTC](https://www.ruby-forum.com/t/xmlhttprequest-on-select-index-change/117625/2 "2007-10-18T19:04:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![metrix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@metrix](https://www.ruby-forum.com/u/metrix)\
**Post date:** [October 18, 2007, 10:02pm UTC](https://www.ruby-forum.com/t/xmlhttprequest-on-select-index-change/117625/3 "2007-10-18T22:02:36Z")

</div>

Frederick

Thanks for point out remote\_function. I’ll go read about it.

---

<div class="post-metadata">

**Author:** ![metrix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@metrix](https://www.ruby-forum.com/u/metrix)\
**Post date:** [October 19, 2007, 12:07am UTC](https://www.ruby-forum.com/t/xmlhttprequest-on-select-index-change/117625/4 "2007-10-19T00:07:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![metrix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@metrix](https://www.ruby-forum.com/u/metrix)\
**Post date:** [October 19, 2007, 1:19am UTC](https://www.ruby-forum.com/t/xmlhttprequest-on-select-index-change/117625/5 "2007-10-19T01:19:29Z")

</div>

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}’))”

---

<div class="post-metadata">

**Author:** ![metrix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@metrix](https://www.ruby-forum.com/u/metrix)\
**Post date:** [October 19, 2007, 1:14am UTC](https://www.ruby-forum.com/t/xmlhttprequest-on-select-index-change/117625/6 "2007-10-19T01:14:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![metrix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@metrix](https://www.ruby-forum.com/u/metrix)\
**Post date:** [October 19, 2007, 10:01am UTC](https://www.ruby-forum.com/t/xmlhttprequest-on-select-index-change/117625/7 "2007-10-19T10:01:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![metrix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@metrix](https://www.ruby-forum.com/u/metrix)\
**Post date:** [October 20, 2007, 12:52am UTC](https://www.ruby-forum.com/t/xmlhttprequest-on-select-index-change/117625/8 "2007-10-20T00:52:55Z")

</div>

Thanks. That is more elegant.
