June 11, 2014

Chechboxlist select all Jquery

I have checkbox list with first element as “"All”. I want to all following operation on this.

1.Click on “All” select all items
2.If I select all items except first item “All”,first item should automatically checked.
3.If I have selected “All” items and I am deselecting any other items “All” should be automatically
   deselected.

Jquery Code block:

$(document).on(‘click’,’[id*=cblYear] input:eq(0)’,function(){
     var toggle = this.checked;
     $”[id*=cblYear] input”.attr(‘checked’,toggle);
}); 

$(document).on(‘click’,’[id*=cblYear] input:gt(0)’,function(){
    if(!this.checked){
      $”[id*=cblYear] input”.eq(0).attr(‘checked’,false);
     }else{
      $”[id*=cblYear] input”.eq(0).attr(‘checked’,$”[id*=cblYear] input”).slice(1).filter
      (‘:not(:checked)’).length ==0
       }

No comments:

Post a Comment