I am facing an issue with a series of individual checkboxes in an ASP form:
<asp:UpdatePanel runat="server" ID="FiltersUpdPnl">
<ContentTemplate>
<div class="filters">
Show:
<asp:DropDownList runat="server" ID="CapNumProjectsDDL" AutoPostBack="true" OnSelectedIndexChanged="GenericFiltersChanged" >
<%--<asp:ListItem Value="0" Text="" Selected="True"></asp:ListItem>--%>
<asp:ListItem Value="1" Text="Capacity"></asp:ListItem>
<asp:ListItem Value="2" Text="Number of Projects"></asp:ListItem>
</asp:DropDownList>
</div>
<div id="filterlist" class="filters">
<span style="font-size:13pt;display:none;">Filters:<asp:Button runat="server"
ID="ApplyFilters1Btn" Text="Apply New Filters" Visible="false" OnClick="ApplyFilters" /> </span>
<br />
<span style="font-size:10pt;">Project Type:</span>
<ul>
<li>
<asp:CheckBox AutoPostBack="true" runat="server" ID="ShowAllChkBx" Text="(check/uncheck all)"
Checked="false" oncheckedchanged="ShowAllChkBx_CheckedChanged" />
</li>
</ul>
<div id="filterchks" runat="server">
<!-- Remaining HTML content goes here -->
The current script to handle the "UncheckParent" functionality is working as expected, but there seems to be an issue when toggling the parent checkbox. The goal is to update all checkboxes within the corresponding div element based on the parent's checked status:
function uncheckParent(checkbox, parentcheckboxid) {
var Parentcheckbox = document.getElementById(parentcheckboxid);
if (!checkbox.checked) {
Parentcheckbox.checked = false;
}
}
function ParentCheck(parent, aId) {
if (parent.checked == false) {
checkByParent(aId, false);
alert("false");
}
else if (parent.checked == true) {
checkByParent(aId, true);
}
}
function checkByParent(aId, aChecked) {
var collection = document.getElementById(aId).getElementsByTagName('INPUT');
for (var x = 0; x < collection.length; x++) {
if (collection[x].type.toUpperCase() == 'CHECKBOX')
collection[x].checked = aChecked;
}
}
Currently, the function always triggers the 'false' alert regardless of the parent checkbox's checked property. I attempted removing the "Checked='true'" property from all checkboxes for troubleshooting purposes, but the behavior persisted.
This feature was initially coded server-side and functioned correctly. However, after some page restructuring and postback event changes, the server began evaluating the checked property during Page_Load before the Event Handler could execute accurately.