views:

44

answers:

1

I downloaded the script from emposha.com/javascript/fcbklistselection-like-facebook-friends-selector.html and made a few modifications, as the source wasn't working as required (When submitting the form, all of the values were being sent to the php handler, not just the checked ones).

My working example is in this Demo.

My issue is this: how can I check a group of <lis> so that I could have a 'Select All' button?

A: 

You can do it like this:

$("#fcbklist li input:checkbox").attr("checked", true);

Or if you want a toggle on that select all box that checks when it's checked, unchecks all when it's not, do this:

$("#selectAll").change(function() {
  $("#fcbklist li input:checkbox").attr("checked", this.checked);
});

To get the effect you want with the plugin though, you'll need to fire a click on the parent as well, like this:

$("#selectAll").change(function() {
  $("#fcbklist li input:checkbox").attr("checked",this.checked).parent().click();
});    ​

You can try a working sample here.

Nick Craver
Thanks for your suggestion Nick. That does indeed checks all the boxes but the background for the individual lis are not being changed. Have you got any other suggestions?Edit---I just saw your final code. You're fantastic Nick. Thanks alot!
Rich
Hi Nick, after a bit of testing I've hit a bug. Click on an li (Not the last two - I've fixed that) then click select all. The initially clicked li's checkbox is still checked but the background has deselected. This is your code that I'm currently using: $("#check_all").change(function() { $(".contactvalues").attr("checked",true).parent().click();});
Rich
@Rich - Try this version, I removed all your in-line handlers, it should be much simpler overall: http://jsfiddle.net/nick_craver/JZ537/2/
Nick Craver
@Nick Craver Again, superb work. I appreciate the help buddy. I hope I'm not overstepping here but I'm going to make one final request (I hope): Alongside the 'Select All' button, can I have buttons that will group selections? Eg - Select all li's with the class = work
Rich
@Rich - You can do it like this: http://jsfiddle.net/nick_craver/JZ537/4/
Nick Craver
@Nick Craver - I'm thinking a bit more out of the box now (Partly inspired by facebook). Can the `<li>'s` be filtered instantly using a search box with ajax/jquery itself?
Rich