# link\_to\_remote passing form values

**URL:** <https://discuss.rubyonrails.org/t/link-to-remote-passing-form-values/11000>\
**Category:** rubyonrails-talk\
**Created:** [March 30, 2007, 12:55am UTC](https://discuss.rubyonrails.org/t/link-to-remote-passing-form-values/11000 "2007-03-30T00:55:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![reed](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@reed](https://discuss.rubyonrails.org/u/reed)\
**Post date:** [March 30, 2007, 12:55am UTC](https://discuss.rubyonrails.org/t/link-to-remote-passing-form-values/11000/1 "2007-03-30T00:55:16Z")

</div>

I need to call a remote function passing data from the current page which a user has enterred.

Trying to do things the rails way the closest I could get was this... \<%= link\_to\_remote 'Remote Call', :url =\> {:action =\> 'add\_device',:serial=\>"$('serial').value"} %\>

It doesn't work though because it makes the "$('serial').value" url safe and passes this string instead of the field value. Note: I tried :escape =\> false but that didn't help.

Below works but is ugly.

\<a href="#" onclick="new Ajax.Request('\<%=url\_for :action =\> 'add\_device', :serial=\>''-%\>' + $('serial').value, {asynchronous:true, evalScripts:true}); return false;"\>Remote Call\</a\>

Does anyone know a better better way to achieve this?

Thanks, Reed

---

<div class="post-metadata">

**Author:** ![Bill\_Walton](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Bill\_Walton](https://discuss.rubyonrails.org/u/Bill_Walton)\
**Post date:** [March 30, 2007, 2:00am UTC](https://discuss.rubyonrails.org/t/link-to-remote-passing-form-values/11000/2 "2007-03-30T02:00:08Z")

</div>

Hi Reed, reed wrote:

> I need to call a remote function passing data from the current page which a user has enterred.
> 
> Trying to do things the rails way the closest I could get was this... \<%= link\_to\_remote 'Remote Call', :url =\> {:action =\> 'add\_device',:serial=\>"$('serial').value"} %\>

Try \<%= link\_to\_remote 'Remote Call', :url =\> {:action =\> 'add\_device',::with =\> "name\_of\_param\_you\_want\_to\_use\_in\_ your\_controller\_to\_access\_the\_value\_of\_the\_field"} %\>

hth, Bill

---

<div class="post-metadata">

**Author:** ![reed](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@reed](https://discuss.rubyonrails.org/u/reed)\
**Post date:** [March 30, 2007, 6:43am UTC](https://discuss.rubyonrails.org/t/link-to-remote-passing-form-values/11000/3 "2007-03-30T06:43:13Z")

</div>

Thanks for that I'm certainly closer to figuring this out than I was, but I'm still having problems...

If I use submit to remote it works... \<%= submit\_to\_remote 'submit\_to\_remote', 'add\_device', :url =\> {:action =\> 'add\_device'}%\> or \<%= submit\_to\_remote 'submit\_to\_remote', 'add\_device', :url =\> {:action =\> 'add\_device'}, :with =\> "Form.serialize(this.form)" %\>

But these don't... \<%= link\_to\_remote 'Add Device', :url =\> {:action =\> 'add\_device'},:with =\>"serial" %\>\<br/\> \<%= link\_to\_remote 'Add Device', :url =\> {:action =\> 'add\_device'},:with =\>"Form.serialize(this.form)" %\>\<br/\> \<%= submit\_to\_remote 'submit\_to\_remote', 'add\_device', :url =\> {:action =\> 'add\_device'}, :with =\> "serial" %\>

---

<div class="post-metadata">

**Author:** ![Bill\_Walton](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Bill\_Walton](https://discuss.rubyonrails.org/u/Bill_Walton)\
**Post date:** [March 30, 2007, 1:08pm UTC](https://discuss.rubyonrails.org/t/link-to-remote-passing-form-values/11000/4 "2007-03-30T13:08:15Z")

</div>

Hi Reed,

reed wrote:

> Thanks for that I'm certainly closer to figuring this out than I was, but I'm still having problems...

Actually, as I re-read your earlier posting, I see I really didn't help much WRT passing back an input value using a link. With a link, you'd definitely need to include the value and I didn't give you that. My bad. I apologize for not reading your post more carefully. Jeff showed you how to pass back all the form's values. Using that approach, you could then pull the param value you wanted out of the hash. AFAIK, it's a safe way to 'pre-submit' form values. Using submit\_to\_remote basically does the same thing, but I would bet it's going to give you problems inasmuch as you'll have more than one submit button within your form.

So let me ask... what exactly are you trying to accomplish? Is it just one user-entered value that you want to pass back? Is it important that the visitor explicitly click a link or button to do that? If not, observe\_field will let you pass a user\_entered value quite easily. If it is more than one field you need to pass, or if you want the visitor to have to explicitly submit the value, then it'll take more. Let us know, before I start guessing and giving you more bad advice ;-p

Best regards, Bill

---

<div class="post-metadata">

**Author:** ![Andrew\_Stewart](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@Andrew\_Stewart](https://discuss.rubyonrails.org/u/Andrew_Stewart)\
**Post date:** [March 30, 2007, 1:59pm UTC](https://discuss.rubyonrails.org/t/link-to-remote-passing-form-values/11000/5 "2007-03-30T13:59:18Z")

</div>

I just encountered something similar so I hope the solution I found helps you:

[http://groups.google.ca/group/rubyonrails-talk/msg/3df638d6c271d8c0](http://groups.google.ca/group/rubyonrails-talk/msg/3df638d6c271d8c0)

Regards, Andy Stewart
