# Check all - check box problem

**URL:** <https://www.ruby-forum.com/t/check-all-check-box-problem/110907>\
**Category:** Rails\
**Created:** [July 31, 2007, 11:50pm UTC](https://www.ruby-forum.com/t/check-all-check-box-problem/110907 "2007-07-31T23:50:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 31, 2007, 11:50pm UTC](https://www.ruby-forum.com/t/check-all-check-box-problem/110907/1 "2007-07-31T23:50:49Z")

</div>

I am not able to create a check box or a button that can check and  
uncheckall the check boxes that i have created. It can be a check box  
or button that checks and unchecks all the check boxes.

\<% i = 0 %\> \<% @hotels.each do |hotel| %\> \<%= check\_box('hotel\_', '', {}, hotel.group\_name+i.to\_s, '') %\> \<% i = i + 1 %\> \<% end %\>

thanks in advance,  
Czar

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 1, 2007, 4:36am UTC](https://www.ruby-forum.com/t/check-all-check-box-problem/110907/2 "2007-08-01T04:36:11Z")

</div>

I think the best way is to use javascript for checking and unchecking  
all. Here is a good example that worked for me when I was doing  
something similar.  
[http://snippets.dzone.com/posts/show/2818](http://snippets.dzone.com/posts/show/2818)  
also [railscasts.com](http://railscasts.com) has a good screencast on checkboxes you might find  
helpful.
