Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] select 'nearly' all checkboxes
- From: wdlists at triche-osborne.com (Triche Osborne)
- Subject: [Javascript] select 'nearly' all checkboxes
- Date: Thu Feb 16 16:56:37 2006
Michael Borchers wrote: > now here is the idea: > the checkboxes belonging to a group are surrounded by a fieldset with an id. > > if i would like to have an "check all boxes of this group" checkbox, is it possible?! > Yes. Include an unnamed checkbox for "all" and attach an onchange event that passes its node to a function, something like this (old-style event attachment just for illustration): <input type="checkbox" onchange="checkAll(this);" /> All In the checkAll function you need to: (1) Test to be sure the "all" box is checked. (If not, the remaining script should not execute. This prevents it firing on an uncheck. Too bad the "onselect" event doesn't work.) (2) If the box was checked, get its parent node, then grab all of the child nodes of that parent. (3) Check the child nodes array for all nodeName == 'INPUT' and set each one's checked attribute to true. (4) For pretty's sake, you can hide the "all" box afterward--or not. Note: The unnamed 'all' will not be included in the $_POST array. I assumed this was the behavior you wanted since including all of the checked fields in the array would render it superfluous anyway. If you do want to include it, just name it. Triche
- References:
- [Javascript] select 'nearly' all checkboxes
- From: Michael Borchers
- [Javascript] select 'nearly' all checkboxes
- Prev by Date: [Javascript] DevToolbar
- Next by Date: [Javascript] Opening new tabs in FireFox.
- Previous by thread: [Javascript] select 'nearly' all checkboxes
- Next by thread: [Javascript] Fw: select 'nearly' all checkboxes
- Index(es):