I'm dealing with a bunch of convaluted code where I cant just add "checked" as the default to the input box. There is a lot going on in this page and I don't want to break it. There are the 3 functions that handle the checkboxes.
Basically this is what it does: There are multiple sectrions of checkboxes. The CheckboxAll will check all of the checkboxes in it's section only.
BlahA CheckboxAll
checkbox1 checkbox2 checkbox3
BlahB CheckboxAll
checkbox4 checkbox5 checkbox6 checkbox7
BlahC CheckboxAll
checkbox8 checkbox9
How do I and where do I default the CheckboxAll boxes to checked?
function SelectAllSystems(form)
{
if (form.SelectAll.checked)
{
<cfif TotSystems gt 10>
if (confirm("\nWARNING. The processing of your application request is subject to delay if you select All Systems. Please be sure to select ONLY the systems that you need access to in order to expedite the processing of your application.\n\nClick OK to continue selection of All Systems.\nClick Cancel to select individual systems."))
</cfif>
{
<cfloop index="x" from="1" to="#TotSystems#">
form.System#x#.checked = true;
</cfloop>
}
<cfif TotSystems gt 10>
else
{
form.SelectAll.checked = false
}
</cfif>
}
else
{
<cfloop index="x" from="1" to="#TotSystems#">
form.System#x#.checked = false;
</cfloop>
}
}
<!---
- parameters: a_PdM:
- int value containing the PdM ID that the systems are in
-
- purpose: If not all check boxes are checked, check them all. However, if
- all the check boxes are checked, uncheck them all.
--->
function toggleAllSystemCheckBoxes(pdmID)
{
<!--- this function is bound to a click event so it checks the state of the input after the mouse-up event --->
var $allPdM = $('#SelectAll_' + pdmID); //get the selectAll checkbox for the pdmID passed (output the selectAll_XXX ID when we render the page)
var $pdmSystems = $('input[type="checkbox"].System_PdM' + pdmID); //get all of the systems associated to that pdmID (output the pdm_XXX class when we render the page)
if($allPdM.is(':checked'))
{
$pdmSystems.attr('checked', 'checked');
}//if
else
{
$pdmSystems.removeAttr('checked');
}//else
}//toggleAllSystemCheckBoxes()
<!---
- parameters: a_PdMID:
- int value containing the PdM ID that the systems are in
-
- purpose: When a system is checked or unchecked, this code runs to make sure
- that the PdM check box is appropriately checked or unchecked
---->
function updateSelectAll(pdmID)
{
var $allPdm = $('#SelectAll_' + pdmID); //get the selectAll checkbox for the pdmID passed (output the selectAll_XXX ID when we render the page)
var $pdmSystems = $('input[type="checkbox"].System_PdM' + pdmID); //get all of the systems associated to that pdmID (output the pdm_XXX class when we render the page)
$pdmSystems.each(function()
{
if(!$(this).is(':checked'))
{
$allPdm.removeAttr('checked');
return false;
}//if
else
{
$allPdm.attr('checked', 'checked');
}//else
})
}//updateSelectAll()
If all of the checkboxes have a class of CheckboxAll:
$('.CheckboxAll').prop("checked",true);
will set all of them to checked.
If you want all of your checkboxes to be checked regardless of class:
$('input:checkbox').prop("checked",true);
will set all of your checkboxes regardless of class to checked.
If you want them all to default on load, look into the document.ready function:
$(document).ready(function() {
$('.CheckboxAll').prop("checked",true);
});