I created this javascript to do two things:
1. check all child checkboxes if select all checkbox is selected.
2. show alert popup if all cases are not complete and user clicks select all checkbox.,
Both these functionalities are working. When I user clicks the select all checkbox, all the child check boxes get checked and if all cases are not complete it also show the alert popup. But the same is done if the user ckicks the select all check box again to uncheck all check boxes.
I dont want the alert popup to show to happen is the user clicks to uncheck the select all checkbox. only all the child checkboxes should be unchecked.
Pls suggest corrections.
<script type="text/javascript">
var TotalChkBx;
var Counter;
var ctrChecked;
window.onload = function () {
//Get total no. of CheckBoxes in side the GridView.
TotalChkBx = parseInt('<%= this.gvConcurrentCases.Rows.Count %>');
//Get total no. of checked CheckBoxes in side the GridView.
Counter = 0;
ctrChecked = (parseInt('<%= this.Label1.Text %>'));
}
function HeaderClick(CheckBox) {
//Get target base & child control.
var TargetBaseControl =
document.getElementById('<%= this.gvConcurrentCases.ClientID %>');
var TargetChildControl = "CheckBoxMerge";
//Get all the control of the type INPUT in the base control.
var Inputs = TargetBaseControl.getElementsByTagName("input");
//Checked/Unchecked all the checkBoxes in side the GridView.
for (var n = 0; n < Inputs.length; ++n)
if (Inputs[n].type == 'checkbox' &&
Inputs[n].id.indexOf(TargetChildControl, 0) >= 0) {
Inputs[n].checked = CheckBox.checked;
}
//Reset Counter
//alert('ctrChecked' + ctrChecked + ' Row# = ' + (parseInt('<%= this.gvConcurrentCases.Rows.Count %>')));
if (ctrChecked < (parseInt('<%= this.gvConcurrentCases.Rows.Count %>')))
alert('All concurrent cases have not been signed out.');
Counter = CheckBox.checked ? TotalChkBx : 0;
}
function ChildClick(CheckBox, HCheckBox) {
//get target control.
var HeaderCheckBox = document.getElementById(HCheckBox);
//Modifiy Counter;
if (CheckBox.checked && Counter < TotalChkBx)
Counter++;
else if (Counter > 0)
Counter--;
//Change state of the header CheckBox.
if (Counter < TotalChkBx)
HeaderCheckBox.checked = false;
else if (Counter == TotalChkBx)
HeaderCheckBox.checked = true;
}
</script>
<asp:CheckBox ID="chkBxHeader" onclick="javascript:HeaderClick(this);" runat="server" />
1. check all child checkboxes if select all checkbox is selected.
2. show alert popup if all cases are not complete and user clicks select all checkbox.,
Both these functionalities are working. When I user clicks the select all checkbox, all the child check boxes get checked and if all cases are not complete it also show the alert popup. But the same is done if the user ckicks the select all check box again to uncheck all check boxes.
I dont want the alert popup to show to happen is the user clicks to uncheck the select all checkbox. only all the child checkboxes should be unchecked.
Pls suggest corrections.
<script type="text/javascript">
var TotalChkBx;
var Counter;
var ctrChecked;
window.onload = function () {
//Get total no. of CheckBoxes in side the GridView.
TotalChkBx = parseInt('<%= this.gvConcurrentCases.Rows.Count %>');
//Get total no. of checked CheckBoxes in side the GridView.
Counter = 0;
ctrChecked = (parseInt('<%= this.Label1.Text %>'));
}
function HeaderClick(CheckBox) {
//Get target base & child control.
var TargetBaseControl =
document.getElementById('<%= this.gvConcurrentCases.ClientID %>');
var TargetChildControl = "CheckBoxMerge";
//Get all the control of the type INPUT in the base control.
var Inputs = TargetBaseControl.getElementsByTagName("input");
//Checked/Unchecked all the checkBoxes in side the GridView.
for (var n = 0; n < Inputs.length; ++n)
if (Inputs[n].type == 'checkbox' &&
Inputs[n].id.indexOf(TargetChildControl, 0) >= 0) {
Inputs[n].checked = CheckBox.checked;
}
//Reset Counter
//alert('ctrChecked' + ctrChecked + ' Row# = ' + (parseInt('<%= this.gvConcurrentCases.Rows.Count %>')));
if (ctrChecked < (parseInt('<%= this.gvConcurrentCases.Rows.Count %>')))
alert('All concurrent cases have not been signed out.');
Counter = CheckBox.checked ? TotalChkBx : 0;
}
function ChildClick(CheckBox, HCheckBox) {
//get target control.
var HeaderCheckBox = document.getElementById(HCheckBox);
//Modifiy Counter;
if (CheckBox.checked && Counter < TotalChkBx)
Counter++;
else if (Counter > 0)
Counter--;
//Change state of the header CheckBox.
if (Counter < TotalChkBx)
HeaderCheckBox.checked = false;
else if (Counter == TotalChkBx)
HeaderCheckBox.checked = true;
}
</script>
<asp:CheckBox ID="chkBxHeader" onclick="javascript:HeaderClick(this);" runat="server" />