Check/uncheck all checkboxes


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?

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;


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs