# AJAX help - proper use of remote\_function

**URL:** <https://www.ruby-forum.com/t/ajax-help-proper-use-of-remote-function/149369>\
**Category:** Rails\
**Created:** [September 24, 2008, 8:53am UTC](https://www.ruby-forum.com/t/ajax-help-proper-use-of-remote-function/149369 "2008-09-24T08:53:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael\_teter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47c2d/32.png) [@michael\_teter](https://www.ruby-forum.com/u/michael_teter)\
**Post date:** [September 24, 2008, 8:53am UTC](https://www.ruby-forum.com/t/ajax-help-proper-use-of-remote-function/149369/1 "2008-09-24T08:53:55Z")

</div>

Hi.

I’m having a hard time understanding how to use remote\_function().

Here’s what I want to do:

I have two divs. The one on the left lists criteria names. When the  
user clicks on one of the entries in the listbox on the left, I want  
to make a remote call to the server to populate the right div based on  
several things: the name of the criteria on the left, and a serialized  
list of the names+selections of the other criteria.

For example, assume the left list is like this:

Continent  
Country  
State  
City

When the user clicks on Continent, I should send a request to the  
server like /reports/get\_criteria\_options

The result will go into a hidden div called crit\_continent. It will  
hold a series of checkboxes and text labels.

The more complicated case is when the user clicks City. I want it to  
send a request like this - /get\_criteria\_options?  
list=city&continent=1,3,4&country=2

I can manually (JavaScript) create the query string, but that may not  
even be necessary given the power of Prototype. In any case, part of  
my confusion is knowing how to even define the remote\_function call  
from within my template.

Here’s what I have right now, as an example (and it doesn’t work  
right)

\<%= remote\_function :update =\> ‘crit\_city’,  
:url =\> { :action =\>  
‘get\_criteria\_options’ },  
:with =\> “$H({list:  
$F(‘crit\_city’), country: $F(‘crit\_country’), state:  
$F(‘crit\_state’)}).toQueryString()” %\>

Unfortunately that results in an error (according to Firebug):  
Form.Element.Serializers[method] is not a function

Googling that error, I see comments about duplicate IDs. I don’t  
think I have dup ids…

I’m very interested in any help or comprehensive non-trivial  
examples. Barring that, I may be open to short-term actual help for  
pay.

Thanks much!  
Michael

---

<div class="post-metadata">

**Author:** ![michael\_teter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47c2d/32.png) [@michael\_teter](https://www.ruby-forum.com/u/michael_teter)\
**Post date:** [September 24, 2008, 10:05am UTC](https://www.ruby-forum.com/t/ajax-help-proper-use-of-remote-function/149369/2 "2008-09-24T10:05:34Z")

</div>

On 24 Sep 2008, at 07:53, michael\_teter wrote:

> 

Probably means that one of those 3 elements (crit\_city etc…) is not  
an input element (or something similar like a select or a textarea).  
It certainly seems suspicious to me that the thing you are updating  
(‘crit\_city’) has the same id as something you are submitting, as you  
had said previously that the point of the exercise was to populate a  
div (which implies that that is what the element with id crit\_city is)

Fred
