CHECKBOX's full select cancel and cross page save method

  • 2020-07-21 07:23:25
  • OfStack

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

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

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

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

function CheckOne() { 
// Verify that you select them all when you click 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 < arr.length; 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 ($conVal.length > 0) { 
$conVal = $conVal.substring(0, $conVal.length - 1); 
} 
$conVal = $conVal + "," + $("#hfDel").val(); 

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

var i = 0; 
var result = ""; 
for (i = 0; i < allArray.length; i++) { 
if (allArray[i] != "") { 
result += allArray[i] + ","; 
} 
} 
if (result.length > 0) { 
result = result.substring(0, result.length - 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 = $conVal.substring(0, $conVal.length - 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 deactivate the selected option ?")) { 
return true; 
} else { 
return false; 
} 
} else { 
alert(" You have not selected the option to deactivate !"); 
return false; 
} 
}); 
}); 

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

Related articles: