# Passing form parameters with remote\_function

**URL:** <https://www.ruby-forum.com/t/passing-form-parameters-with-remote-function/78703>\
**Category:** Rails\
**Created:** [December 7, 2006, 11:22pm UTC](https://www.ruby-forum.com/t/passing-form-parameters-with-remote-function/78703 "2006-12-07T23:22:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 7, 2006, 11:22pm UTC](https://www.ruby-forum.com/t/passing-form-parameters-with-remote-function/78703/1 "2006-12-07T23:22:15Z")

</div>

If I write a GET AJAX request using remote function, how can I configure  
it to pass the values of form fields.

Assume that I have a ZIP code field in a form, and I write something  
like this:

remote\_function(:url =\> {:action =\> ‘lookup\_city\_and\_state’,  
:object\_name =\> object\_name,  
:check\_state =\> check\_state ? ‘1’ : ‘0’,  
:mailing =\> mailing ? ‘1’ : ‘0’})

how would I pass the form value from my ZIP code field - or can it be  
done?

I already have the Javascript version of this AJAX request working but  
was wondering if I could use the remote\_function idiom instead.

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 8, 2006, 12:25am UTC](https://www.ruby-forum.com/t/passing-form-parameters-with-remote-function/78703/2 "2006-12-08T00:25:24Z")

</div>

Wes,

Did you try the :with option?

e.g

:onclick =\> remote\_function(  
:url =\> {:action =\> :preview},  
#:with =\> “‘name\_of\_form\_field’=value\_you\_want\_and\_javascript\_is\_legal”  
:with =\>  
“‘patch[editing\_rdoc]=’+$(‘patch\_modified\_rdoc\_source’).value”,  
:before =\> “$(‘preview\_target’).innerHTML=’…loading…’”,  
:failure =\> “$(‘preview\_target’).innerHTML=‘Ajax error!’”,  
:update =\> ‘preview\_target’  
) + ‘;return false;’

–Jinal

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 8, 2006, 12:27am UTC](https://www.ruby-forum.com/t/passing-form-parameters-with-remote-function/78703/3 "2006-12-08T00:27:25Z")

</div>

Also you can use the submit option

\<%= submit\_tag ‘Save’, :name =\> ‘save’, :id =\> ‘save’ %\>  
\<%= submit\_tag ‘Update Preview’,  
:name =\> ‘preview’,  
:onclick =\> remote\_function(  
:url =\> {:action =\> :preview, :\_method =\> :post},  
:submit =\> “id\_of\_my\_form”,  
:before =\> “$(‘preview\_target’).innerHTML=‘…loading…’”,  
:failure =\> “$(‘preview\_target’).innerHTML=‘Ajax error!’”,  
:update =\> ‘preview\_target’  
) + ‘;return false;’  
%\>

Read [http://www.timocracy.com/articles/tag/remote\_function](http://www.timocracy.com/articles/tag/remote_function) for detailed  
information on various ways of doing this.

–Jinal Jhaveri

> **[Google Sites: Sign-in](https://accounts.google.com/v3/signin/identifier?dsh=S1224935652%3A1689728336267761&continue=https%3A%2F%2Fsites.google.com%2Fsite%2Fsites%2Fsystem%2Ferrors%2FWebspaceNotFound%3Fpath%3D%2Fjjhaveri%2F&followup=https%3A%2F%2Fsites.google.com%2Fsite%2Fsites%2Fsystem%2Ferrors%2FWebspaceNotFound%3Fpath%3D%2Fjjhaveri%2F&ifkv=AeDOFXj7i-pMC3phWTQ7kGmOknKcSaYKQ6_RNZeqkPcaCyosSI-jHyJQFnxmXJ8gZtEydibkl8dVpA&passive=1209600&service=jotspot&flowName=GlifWebSignIn&flowEntry=ServiceLogin)**
>
> Access Google Sites with a personal Google account or Google Workspace account (for business use).

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 8, 2006, 7:55am UTC](https://www.ruby-forum.com/t/passing-form-parameters-with-remote-function/78703/4 "2006-12-08T07:55:00Z")

</div>

Jinal,

Thanks. I thought :with might work but didn’t see it in the API docs.

Generally, I find that finding a true comprehensive list of Prototype  
API function parameters, or finding a comprehensive list of RoR AJAX-y  
function parameters can be somewhat challenging.

I wonder if anyone is working on a _complete_ Prototype/Script.aculo.us  
reference?

Anyhow, thanks again, all works great.

Wes
