(function($) {
$.fn.extend({
checkun: function(options) {
var defaults = {
chkAllName : "",
chkBoxName : ""
}
var options = $.extend(defaults, options);
var chkAll = options.chkAllName;
var chkBoxs = options.chkBoxName;
var chkBoxesLength = $("input[name='"+chkBoxs+"']").length;
$("input[name='"+chkAll+"']").click(function() {
//get checked state of chkAll checkbox
var chkState = $(this).attr("checked");
if(chkState) {
$("input[name='"+chkBoxs+"']").attr("checked", true);
}
else {
$("input[name='"+chkBoxs+"']").attr("checked", false);
}
});
$("input[name='"+chkBoxs+"']").click(function() {
var subChkState = $(this).attr("checked");
if(subChkState) {
//get the total checkboxes and total checked checkboxes
var chkedLen = $("input[name='"+chkBoxs+"']:checked").length;
if(chkedLen == chkBoxesLength) {
$("input[name='"+chkAll+"']").attr("checked", true);
}
}
else {
//uncheck the chkAll checkbox
$("input[name='"+chkAll+"']").attr("checked", false);
}
});
}
});
})(jQuery);
And to test it, we use the following
//load jquery.js
// Check All
//
//
Thats it. Hope this helps someone.
1 comment:
Thanks,
this is nice one works for me easly. Very nice post thanks again keep it up.
Post a Comment