# Remote\_function :with parameters from other form fields

**URL:** <https://www.ruby-forum.com/t/remote-function-with-parameters-from-other-form-fields/131624>\
**Category:** Rails\
**Created:** [March 12, 2008, 12:28am UTC](https://www.ruby-forum.com/t/remote-function-with-parameters-from-other-form-fields/131624 "2008-03-12T00:28:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lunaclaire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f4b2a3/32.png) [@lunaclaire](https://www.ruby-forum.com/u/lunaclaire)\
**Post date:** [March 12, 2008, 12:28am UTC](https://www.ruby-forum.com/t/remote-function-with-parameters-from-other-form-fields/131624/1 "2008-03-12T00:28:01Z")

</div>

I’m building a form where I have a set of radio buttons. When any of  
these are selected I make an AJAX call that needs some values from  
other fields in the form, but I’m having problems getting those values  
and maybe someone can help.

I have the following code which is essentially repeated for each of  
the radio buttons:

\<%= radio\_button\_tag(:recurrence\_period,  
CalendarRepeatingEvent::RECURRENCE\_PERIOD\_MONTHLY\_BY\_DATE,  
@recurrence\_period ==  
CalendarRepeatingEvent::RECURRENCE\_PERIOD\_MONTHLY\_BY\_DATE, {:onchange  
=\> remote\_function(:with =\> “‘recurrence\_period=’+this.value  
+’&recurrence\_frequency=#{@recurrence\_frequency}&occurrence\_number=#{@occurrence\_number}’”,  
:url  
=\> {:action =\> ‘select\_recurrence\_period’ })}) %\>  
Monthly

Note that the 2 values I’m trying to pass back are where I have  
@recurrence\_frequency and @occurrence\_number… these are just  
placeholders because they’re really instance variables passed when the  
form is initially setup and I just wanted to see if something got  
passed back.

elsewhere in the form are the elements (id=‘frequency’ and id=‘count’)  
I want to pull values from and pass back… here’s that code:

Every:  
Frequency:  
  
\<%= text\_field\_tag(:recurrence\_frequency, @recurrence\_frequency, :size  
=\> 2) %\>  
   
  
  
  
  
How many times?  
  
\<%= text\_field\_tag(:occurrence\_number, @occurrence\_number, :size =\> 4)  
%\>

(I hope this code is easy to read as sposted)

I tried using the Prototype utility method $F to pull the values (e.g.  
$F(‘frequency’)), but either that doesnt work or I’m doing it wrong.

Anybody familiar with this kind of problem?

---

<div class="post-metadata">

**Author:** ![lunaclaire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f4b2a3/32.png) [@lunaclaire](https://www.ruby-forum.com/u/lunaclaire)\
**Post date:** [March 12, 2008, 4:22pm UTC](https://www.ruby-forum.com/t/remote-function-with-parameters-from-other-form-fields/131624/2 "2008-03-12T16:22:21Z")

</div>

I’d suggest wrapping everything in a larger container, and then use  
the handy observe\_form helper.

 ... radio buttons... ... frequency ... ...occurence...
\<%= observe\_form 'schedule', :url=\>your\_target\_path %\>

This approach will serialize the input elements of ‘schedule’ (the  
container) any time any one of them changes. You don’t need to add  
all that messy js script to your checkboxes – the helper renders one  
observer that handles it for you.

---

<div class="post-metadata">

**Author:** ![lunaclaire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f4b2a3/32.png) [@lunaclaire](https://www.ruby-forum.com/u/lunaclaire)\
**Post date:** [March 14, 2008, 8:59pm UTC](https://www.ruby-forum.com/t/remote-function-with-parameters-from-other-form-fields/131624/3 "2008-03-14T20:59:02Z")

</div>

Thanks, Andy!

I changed the form before I got your answer, but observer\_form looks  
good… thx for the tip.
