# Check/uncheck all checkboxes

**URL:** <https://www.ruby-forum.com/t/check-uncheck-all-checkboxes/101297>\
**Category:** Rails\
**Created:** [February 5, 2006, 5:45pm UTC](https://www.ruby-forum.com/t/check-uncheck-all-checkboxes/101297 "2006-02-05T17:45:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ed8c4c/32.png) [@jay](https://www.ruby-forum.com/u/jay)\
**Post date:** [February 5, 2006, 5:45pm UTC](https://www.ruby-forum.com/t/check-uncheck-all-checkboxes/101297/1 "2006-02-05T17:45:09Z")

</div>

Hello!

I have this page where I list all users in a table. There is checkbox in  
every row. My User-model has a “checked”-attribute.

I have implemented the checkboxes like this:  
\<%= check\_box(“user[]”, “checked”) %\>

Which outputs this:

How can i check/uncheck all checkboxes in one click? Do I have to use  
javascript and have onClick()-event?

---

<div class="post-metadata">

**Author:** ![jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ed8c4c/32.png) [@jay](https://www.ruby-forum.com/u/jay)\
**Post date:** [February 5, 2006, 8:03pm UTC](https://www.ruby-forum.com/t/check-uncheck-all-checkboxes/101297/2 "2006-02-05T20:03:58Z")

</div>

use an onclick for a button or something and send the form thru this

function checkAll(theForm) {

var z = 0;

while (theForm[z].type == ‘checkbox’ ) {  
theForm[z].checked = true;  
z++;  
}  
}

adam
