$(function(){
var l = $(‘.cb’).length; //NUMBER OF CHECKBOXES
//WHEN CHECKBOXES ARE CLICKED
$(‘.cb’).live(“click”, function(){
var q = $(this).index(‘.cb’); //CHECKBOX INDEX
var v = $(‘.tb:eq(‘+q+’)’).text(); //ITS VALUE
//CHECKS OR UNCHECKES AND INPUTS VALUE FROM ITS ADJACENT TEXT
if(!$(this).hasClass(‘s’)){
$(this).addClass(‘s’).val(v); //ADDS THE STYLISH CHECKBOX, GIVES INPUT VALUE
} else {
$(this).removeClass(‘s’).val(”);
}
var m = $(‘.s’).length; //NUMBER OF CHECKED BOXED
//IF ALL CHECKBOXES ARE CHECKED, HIDE “CHECK ALL” BUTTON
if(m==l){
$(‘#c’).hide();
} else {
$(‘#c’).show(); //MAINTAINS VISIBILITY
}
//IF NO CHECKBOXES ARE CHECKED, HIDE “UNCHECK ALL” BUTTON
if(m==0){
$(‘#u’).hide();
} else {
$(‘#u’).show(); //MAINTAINS VISIBILITY
}
});
//”CHECK ALL” FUNCTION
$(‘#c’).live(“click”, function(){
//GIVES VALUE TO EACH CHECKBOX FROM ITS ADJACENT TEXT
$(‘.cb’).each(function(){
var q = $(this).index(‘.cb’); //CHECKBOX INDEX
var v = $(‘.tb:eq(‘+q+’)’).text(); //ITS VALUE
$(this).addClass(‘s’).val(v); //ADDS THE STYLISH CHECKBOX, GIVES INPUT VALUE
});
$(this).hide(); //HIDES THE BUTTON
$(‘#u’).show(); //KEEPS THE “UNCHECK ALL” BUTTON
});
$(‘#u’).live(“click”, function(){
$(‘.cb’).removeClass(‘s’).val(”); //REMOVES EACH STYLISH CHECKBOX AND ITS VALUE
$(this).hide(); //HIDES THE BUTTON
$(‘#c’).show(); //KEEPS THE “CHECK ALL” BUTTON
});
//SHOWS THE VALUE OF EACH CHECKED ELEMENTS
$(‘.cb, #c, #u’).live(“click”, function(){
var s = ”; //BLANK VARIABLE UNTIL THE “FOR LOOP”
var m = $(‘.s’).length; //NUMBER OF CHECKED BOXED
for(i=0; i