# Ajax submit question

**URL:** <https://www.ruby-forum.com/t/ajax-submit-question/167064>\
**Category:** Rails\
**Created:** [May 3, 2009, 7:41am UTC](https://www.ruby-forum.com/t/ajax-submit-question/167064 "2009-05-03T07:41:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [May 3, 2009, 7:41am UTC](https://www.ruby-forum.com/t/ajax-submit-question/167064/1 "2009-05-03T07:41:58Z")

</div>

Is there a way to do an ajax submit but only send the values in an  
embedded form inside a form?

I have to do an ajax submit with multiple companies and I get this  
being submitted for the post:

companyid 1  
companyid 2  
companyid 3

If I have multiple submits possible but I need to be able to get the  
appropriate company id that is submitted.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [May 3, 2009, 11:42am UTC](https://www.ruby-forum.com/t/ajax-submit-question/167064/2 "2009-05-03T11:42:45Z")

</div>

On May 3, 6:41 am, Me [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there a way to do an ajax submit but only send the values in an  
> embedded form inside a form?

nested forms are not allowed by the html standard. When making an ajax  
request you can however submit an arbitrary element to submit.

Fred

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [May 3, 2009, 4:45pm UTC](https://www.ruby-forum.com/t/ajax-submit-question/167064/3 "2009-05-03T16:45:34Z")

</div>

I have been using fields\_for for my inline ajax forms. How do submit  
text  
fields using a button\_to\_function?  
I have several inline forms using ajax calls to do CRUD for my contact  
info.

On Sun, May 3, 2009 at 4:42 AM, Frederick C.  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [May 3, 2009, 5:18pm UTC](https://www.ruby-forum.com/t/ajax-submit-question/167064/4 "2009-05-03T17:18:24Z")

</div>

I have this ajax form that could be disaplyed multiple times on the  
page:  
If it is displayed multiple times when i do the ajax submit I get those  
same fields submitted. Is there a way to differentiate between them  
all?

\<% fields\_for :site do |f|%\>  
\<%= f.text\_field “company”,’’, :size =\> ‘6’ %\>  
\<%= f.text\_field “Customer”,’’, :size =\> ‘6’ %\>  
\<%= hidden\_field\_tag ‘companyid’,’’, :value =\> @company.id %\>  
\<%= submit\_to\_remote ‘addsite’,‘Add Site’, :url =\> { :controller =\>  
‘addsites’, :action =\> ‘addsitetomop’, :id=\> @mop }%\>

\<% end %\>

In firebug this is what it looks like:

site[Customer]  
site[Customer]  
site[company]  
site[company]  
.

If I do a “button\_to\_function remote\_function” is there a way to send  
the  
text fields values across?

On Sun, May 3, 2009 at 4:42 AM, Frederick C.  
\<removed\_email\_address@domain.invalid
