Forum: Ruby on Rails Check/uncheck all checkboxes

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jay (Guest)
on 2006-02-05 18:45

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:
<input id="user_12_checked" name="user[12][checked]" type="checkbox"
value="1" /><input name="user[12][checked]" type="hidden" value="0" />

How can i check/uncheck all checkboxes in one click? Do I have to use
javascript and have onClick()-event?
Adam D. (Guest)
on 2006-02-05 21:03
(Received via mailing list)
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 topic is locked and can not be replied to.