Forum: Ruby on Rails Check/uncheck all checkboxes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ae1578a64c07d63e32b2476c7ac8b1cd?d=identicon&s=25 Jay (Guest)
on 2006-02-05 17:45
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:
<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?
F15fdc7cb2e911b3808837f2be244add?d=identicon&s=25 Adam Denenberg (Guest)
on 2006-02-05 20: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;
    z++;
   }
}


adam
This topic is locked and can not be replied to.