# Check boxes check all tips

**URL:** <https://www.ruby-forum.com/t/check-boxes-check-all-tips/68711>\
**Category:** Rails\
**Created:** [September 14, 2006, 6:21pm UTC](https://www.ruby-forum.com/t/check-boxes-check-all-tips/68711 "2006-09-14T18:21:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chester\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ce73a5/32.png) [@Chester\_C](https://www.ruby-forum.com/u/Chester_C)\
**Post date:** [September 14, 2006, 6:21pm UTC](https://www.ruby-forum.com/t/check-boxes-check-all-tips/68711/1 "2006-09-14T18:21:42Z")

</div>

Hi,

Pardon me if this question is already asked. I wonder if anyone know  
where I can find the snippet of code that will allow me to do “check  
all” and “uncheck all” in a list view of items. I am trying to see if  
there is any rails api i can use instead of “raw” javascript. Thanks in  
advance.

Regards,  
Chester

---

<div class="post-metadata">

**Author:** ![Chester\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ce73a5/32.png) [@Chester\_C](https://www.ruby-forum.com/u/Chester_C)\
**Post date:** [September 14, 2006, 7:13pm UTC](https://www.ruby-forum.com/t/check-boxes-check-all-tips/68711/2 "2006-09-14T19:13:05Z")

</div>

pass it the form id and true/false and this should do it:

function toggleCheck (form\_id, checked) {  
var form = $(form\_id);  
for (var i = 0; i \< form.elements.length; i++) {  
form.elements[i].checked = checked;  
}  
}

On 9/14/06, Chester C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Regards,  
> Chester
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ed Hickey  
Developer  
Litmus Media  
816-533-0409  
removed\_email\_address@domain.invalid  
A Member of Think Partnership, Inc  
[www.ThinkPartnership.com](http://www.ThinkPartnership.com)  
Amex ticker symbol: THK

---

<div class="post-metadata">

**Author:** ![Chester\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ce73a5/32.png) [@Chester\_C](https://www.ruby-forum.com/u/Chester_C)\
**Post date:** [September 14, 2006, 7:29pm UTC](https://www.ruby-forum.com/t/check-boxes-check-all-tips/68711/3 "2006-09-14T19:29:08Z")

</div>

This should select and check all the inputs in the element with id  
‘#container’  
to uncheck them, just change the checked to false

```
<%=link_to_function "Select All", update_page {|page|

```

page.select(‘#container input’).each {|x|x.checked = true}}%\>

e.g this will check the following checkboxes

 i love ruby i love rails

Hope this helps!

Cheery-O!  
Gustav  
removed\_email\_address@domain.invalid

> **[ItsDex.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=itsdex.com)**
>
> We help you acquire the perfect domain for your site. Affordable payment options. Quick and responsive customer support available.
