# Check\_box\_tag remote\_function

**URL:** <https://www.ruby-forum.com/t/check-box-tag-remote-function/130739>\
**Category:** Rails\
**Created:** [March 2, 2008, 10:57pm UTC](https://www.ruby-forum.com/t/check-box-tag-remote-function/130739 "2008-03-02T22:57:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bucks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cab0a1/32.png) [@bucks](https://www.ruby-forum.com/u/bucks)\
**Post date:** [March 2, 2008, 10:57pm UTC](https://www.ruby-forum.com/t/check-box-tag-remote-function/130739/1 "2008-03-02T22:57:03Z")

</div>

I have a collection of check\_box\_tags that look like the following:

\<% for item in @items %\>  
\<%= check\_box\_tag “item[item\_ids][]”, item.id, false, {:onchange =\>  
remote\_function(:url =\> update\_items\_path, :with =\> "‘items=’ +  
escape(value) "} %\>  
\<%= item.name %\>  
\<% end %\>

My question is, how do I send all of the current checkbox values  
(item[item\_ids][]) in the onchange? Currently, I am only getting the  
value of the changed checkbox (ie: items=2), but I need to know which  
other checkboxes are checked.

Thanks,  
bucks

---

<div class="post-metadata">

**Author:** ![bucks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cab0a1/32.png) [@bucks](https://www.ruby-forum.com/u/bucks)\
**Post date:** [March 3, 2008, 7:11pm UTC](https://www.ruby-forum.com/t/check-box-tag-remote-function/130739/2 "2008-03-03T19:11:00Z")

</div>

Is there a reason not to manage ONLY the change, rather than trying to  
manage the entire collection on each change? Seems like it’d be more  
efficient to take the id/value that you receive and either to a  
x.items \<\< Item.find(id) or x.items.delete Item.find(id). Regardless,  
it sounds like you’d want either an observe\_form (sees all the changes  
and submits the entire form) or you could wrap up the check boxes in  
some container (fieldset, div, etc), give the container a name, and  
then use:

remote\_function(:url=\>…, :submit=\>‘container\_id’)

That will serialize the values of all the input elements in the  
container. Note that you’ll only receive the ids of check boxes that  
are checked.

---

<div class="post-metadata">

**Author:** ![bucks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cab0a1/32.png) [@bucks](https://www.ruby-forum.com/u/bucks)\
**Post date:** [March 4, 2008, 6:26pm UTC](https://www.ruby-forum.com/t/check-box-tag-remote-function/130739/3 "2008-03-04T18:26:01Z")

</div>

Thanks for the response. Definitely some good options. I think I will  
give the :submit =\> ‘container\_id’ a shot, as it seems most inline  
with what i’m trying to do.

Cheers,
