# Form\_remote\_tag and :with

**URL:** <https://www.ruby-forum.com/t/form-remote-tag-and-with/150080>\
**Category:** Rails\
**Created:** [October 3, 2008, 8:43am UTC](https://www.ruby-forum.com/t/form-remote-tag-and-with/150080 "2008-10-03T08:43:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [October 3, 2008, 8:43am UTC](https://www.ruby-forum.com/t/form-remote-tag-and-with/150080/1 "2008-10-03T08:43:55Z")

</div>

I am trying to pass the result from a javascript function along with  
the result from a text\_field with form\_remote\_tag. This is what I  
have so far, but no go:

```
<% form_remote_tag(:url => {:controller => 'requests', :action =>

```

‘create’}, :with =\> “‘data=’+request()”, :update =\> ‘request\_sent’ )  
do %\>  
\<%= text\_field “request”, “request” %\>  
  
\<%= submit\_tag ‘Send Request’ %\>  
\<% end %\>

I was able to get this to work with link\_to\_remote with the following  
code:

\<%= link\_to\_remote ‘Update availability’, :url =\> {:action =\>  
“array”}, :with =\> “‘data=’+test()”, :update =\> ‘testing’ %\>

where test() is the javascript function. This allows me to access the  
result of the test function in params[:data]. It seems that I should  
be able to do the same with form\_remote\_tag, but I have been  
unsuccessful. Maybe a syntax mistake? Maybe not possible?

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [October 4, 2008, 3:46am UTC](https://www.ruby-forum.com/t/form-remote-tag-and-with/150080/2 "2008-10-04T03:46:14Z")

</div>

result() is the name of a javascript function that I have defined  
within a script in the head element. calling it in :with sets this  
result to data, which can then be accessed with params[:data] in the  
action create.

On Oct 3, 1:34 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [October 4, 2008, 4:23am UTC](https://www.ruby-forum.com/t/form-remote-tag-and-with/150080/3 "2008-10-04T04:23:42Z")

</div>

So this returns the correct value in params[:data]:  
\<%= link\_to\_remote ‘Send Request’, :url =\> {:controller =\>  
“requests”, :action =\> “create”,  
:date =\> @date, :weekday =\> @weekday, :id =\> @id}, :with =\>  
“‘data=’+newFunction()”,  
:update =\> ‘request\_sent’ %\>

but this returns nil:  
\<% form\_remote\_tag(:url =\> {:controller =\> ‘requests’, :action  
=\>‘create’},  
:with =\> “‘data=’+newFunction()”, :update =\> ‘request\_sent’)  
do %\>  
\<%= text\_field “request”, “request” %\>  
  
\<%= submit\_tag ‘Send Request’ %\>

am I using :with within the form\_remote\_tag helper correctly? Are you  
able to use it with form\_remote\_tag? Thanks.

On Oct 3, 1:46 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [October 4, 2008, 4:33am UTC](https://www.ruby-forum.com/t/form-remote-tag-and-with/150080/4 "2008-10-04T04:33:39Z")

</div>

Oh i forgot to include the \<% end %\> code. I have that and it still  
does not work.

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [October 17, 2008, 7:01am UTC](https://www.ruby-forum.com/t/form-remote-tag-and-with/150080/5 "2008-10-17T07:01:21Z")

</div>

can anyone help with this syntax? I figure anything that works for  
link\_to\_remote has got to work for form\_remote\_tag. Does anyone know  
if its possible to use the :with to pass parameters using  
form\_remote\_tag? This is what I have so far, but the params[:time]  
passed in :with is still nil and it works with link\_to\_remote.

```
<%= form_remote_tag :url => {:controller => 'requests', :action

```

=\>‘create’, :month =\> @month,  
:day\_number =\> @day\_number, :day\_name =\> @day\_name, :id =\>  
@id},  
:with =\> “‘time=’+timeReturn()”, :update =\> ‘request\_sent’ %\>  
\<%= text\_field “request”, “request” %\>  
  
\<%= submit\_tag(‘Send Request’) %\>  
\<% end -%\>

All the other params, i.e. month and day\_number are passed, so i know  
the general syntax is working, its just the :with that is giving me a  
problem.

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [October 17, 2008, 8:37am UTC](https://www.ruby-forum.com/t/form-remote-tag-and-with/150080/6 "2008-10-17T08:37:23Z")

</div>

turns out you need to use submit\_to\_remote:

\<% form\_tag :url =\> {:controller =\> ‘foo’, :action =\>‘bar’, :month =\>  
@month,  
:day\_number =\> @day\_number, :day\_name =\> @day\_name, :id =\> @id} do  
%\>  
\<%= text\_field “request”, “request” %\>  
  
\<%= submit\_to\_remote(‘submit’, ‘Send Request’, :url =\>  
{:controller =\> ‘foo’, :action =\>‘bar’, :month =\> @month,  
:day\_number =\> @day\_number, :day\_name =\> @day\_name, :id =\>  
@id},  
:with =\> “‘time=’+timeReturn()”, :update =\>  
‘request\_sent’, :confirm =\> “sure?”) %\>  
\<% end %\>
