I have a recordset on a page listing some items, and have a checkbox for each to insert records into another table.
I have been looking at JS to be able to check / uncheck all the checkboxes, but without any luck.
The closest I got was the JS:
<script type="text/javascript">
function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
if(!document.forms[FormName])
return;
var objCheckBoxes = document.forms[FormName].elements[FieldName];
if(!objCheckBoxes)
return;
var countCheckBoxes = objCheckBoxes.length;
if(!countCheckBoxes)
objCheckBoxes.checked = CheckValue;
else
// set the check value for all check boxes
for(var i = 0; i < countCheckBoxes; i++)
objCheckBoxes[i].checked = CheckValue;
}
</script>
Which works so long as the name of the checkbox is a constant,e.g.:
<input name="LodgeIDPL" id="LodgeIDPL_<?php echo $RepeatSelectionCounter_1; ?>" type="checkbox" value="<?php echo($row_WADAlodges['LodgeID']); ?>" />
With these as the form buttons:
<input type="button" onclick="SetAllCheckBoxes('Insert_Basic_Default', 'LodgeIDPL', true);" value="Select All Products">
<input type="button" onclick="SetAllCheckBoxes('Insert_Basic_Default', 'LodgeIDPL', false);" value="Deselect All Products">
But because the name includes an extra bit for the multiple insert function, it breaks it:
<input name="LodgeIDPL_<?php echo $RepeatSelectionCounter_1; ?>" id="LodgeIDPL_<?php echo $RepeatSelectionCounter_1; ?>" type="checkbox" value="<?php echo($row_WADAlodges['LodgeID']); ?>" />
If anyone could help out with a way to retain the counter for the multiple insert, and allow users to select / deselect all the checkboxes that would be really appreciated.
Thanks.