Hi Phil,

On 17.10.2010, at 18.15, Phil Petree wrote:

> OK, I have a form where the first row of the first colum is a checkbox 
> designed to toggle the checked/unchecked state of all the other checkboxes in 
> the form (select all/select none).
>  
> Problem is, the state of the checkbox with the onclick state is not getting 
> changed.  The rest of the check boxes are toggling based on their current 
> state and I want to tie them to the "master" checkbox and I'm just not 
> getting this to work.

Your HTML code is invalid in a few ways. From a quick glimpse, you have divs 
inside tr's and the form element as a direct descendant of table. The latter 
especially causes some trouble. At least Safari automatically closes the form 
element and thus the checkboxes won't fall within the form. Thus your code 
below can't possibly work.

Here's a quick script that seemed to work (at least in Safari console) with 
your example page:

$('toggle_all').observe('click', function(ev) {
  var self = this;
  $$('input[type=checkbox]').without(this).each(function(el) {
    el.checked = self.checked;
  });
});

You probably want to modify the selector to be more precise and maybe make the 
whole function more generic, though.

//jarkko

>  
> A sample page is here:
> http://www.neighborhoodwatchalerts.com/invite/checkboxes.php
>  
> The code is this:
> function toggleCheckBoxes(formName)
> {
> // toggle Check Boxes using Prototype Library
>  var form = $(formName);
>  var i = form.getElements('checkbox');
>  var chkState = ($F('toggle_all') == "on") ? true : false;
> // alert("chkState = " +chkState);  // show the current state
>     
>   i.each(function(item, chkState)
>   {
> //    item.checked = chkState;  // set all checkboxes to the masters state
> //    if (chkState == false) // turn all checkboxes off
>     if (item.checked)
>     {
>       item.checked=false;
>     }
>   else
>     {
>       item.checked=true;
>     }
>  }
>   );
>   return true;
> } 
>  
> Any thoughts or suggestions?  TJ, you have have any other shortcuts tucked 
> away?
>  
> Thanks,
>  
> Pete
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Prototype & script.aculo.us" group.
> To post to this group, send email to prototype-scriptacul...@googlegroups.com.
> To unsubscribe from this group, send email to 
> prototype-scriptaculous+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/prototype-scriptaculous?hl=en.

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://odesign.fi

Check out my latest book, Unobtrusive Prototype, fresh off the Peepcode oven:
http://peepcode.com/products/unobtrusive-prototype-js

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to