SoFunction
Updated on 2025-03-09

Implementation methods of selecting all, canceling and spreading page saving of CHECKBOX


<script>
$(document).ready(function () {
/**
*Select checkbox all
*/
$(".checkall").live("click", function () {
if ($(this).attr("checked") == "checked") {//If selected
CheckAll();
} else {
UnCheckAll();
}
UpdateHfValues();
});

$(".checkone").each(function () {
$(this).live("click", function () {
CheckOne();
UpdateHfValues();
});
});

function UnCheckAll() {
//Cancel all selection
$(".checkone").each(function () {
$(this).removeAttr("checked");
});
}

function CheckAll() {
//Select all
$(".checkone").each(function () {
$(this).attr("checked", "checked");
});
}

function CheckOne() {
//Check whether all are selected when clicking a single message
var $length = $(".checkone").length;
var $checklenght = $(".checkone:checked").length;
if ($length == $checklenght) {
$(".checkall").attr("checked", "checked");
} else {
$(".checkall").removeAttr("checked");
}
}
var arr = $("#hfDel").val().split(",");
$(".checkone").each(function () {
var i = 0;
for (i = 0; i < ; i++) {
if (arr[i] == $(this).val()) {
$(this).attr("checked", "checked");
}
}
});
var checkedNum = $(".checkone:checked").length;
var allNum = $(".checkone").length;
if (checkedNum == allNum) {
$(".checkall").attr("checked", "checked");
}

function UpdateHfValues() {
var $checkOneLen = $(".checkone:checked").length;
var $conVal = "";
$(".checkone:checked").each(function (i) {
$conVal += $(this).val() + ",";
});
if ($ > 0) {
$conVal = $(0, $ - 1);
}
$conVal = $conVal + "," + $("#hfDel").val();

var allArray = $(",");
$(".checkone").each(function () {
if (typeof $(this).attr("checked") != "undefined" && $(this).attr("checked") == "checked") {
var i = 0;
var find = false;
for (i = 0; i < ; i++) {
if (allArray[i] == $(this).val()) {
find = true;
}
}
if (find == false) {
($(this).val());
}
}
else {
var i = 0;
for (i = 0; i < ; i++) {
if (allArray[i] == $(this).val()) {
allArray[i] = "";
}
}
}
});

var i = 0;
var result = "";
for (i = 0; i < ; i++) {
if (allArray[i] != "") {
result += allArray[i] + ",";
}
}
if ( > 0) {
result = (0, - 1);
}

$("#hfDel").val(result);
}

function UpdateValues() {
alert($("#hfDel").val());
var $checkOneLen = $(".checkone:checked").length;
var $conVal = "";

$(".checkone:checked").each(function (i) {
$conVal += $(this).val() + ",";
});

$conVal = $(0, $ - 1);

$("#hfDel").val($conVal);
}

$("#btnDeletes").unbind("click").live("click", function () {
if ($("#hfDel").val() != "") {
if (confirm("Are you sure you want to enable the selected option?")) {
return true;
} else {
return false;
}
} else {
alert("You have not selected the option to enable!");
return false;
}
});

$("#lbTingYong").unbind("click").live("click", function () {
if ($("#hfDel").val() != "") {
if (confirm("Are you sure you want to disable the selected option?")) {
return true;
} else {
return false;
}
} else {
alert("You have not selected the option to deactivate!");
return false;
}
});
});

<script>
<input type="checkbox" class="checkall" onclick="checkAll(this)" /></div>
<input type="checkbox" class="checkone" value='<%#Eval("cSubjectDetailID") %>' />
<asp:HiddenField ID="hfDel" runat="server" />