Syntax for JS to select all checkboxes

Thanks of that. Can’t get it to work though.

I have the JS just after my body tag:

<script language="JavaScript">
function selectAll(source) {
var inputs = document.getElementById('AveragePricesForm').getElementsByTagName('input');
for(var i in inputs) {
    if(inputs[i].type === 'checkbox') {
        inputs[i].checked = source.checked;
    }
  }
}
</script>

My form tag:

<form name="AveragePricesForm" id="AveragePricesForm" method="POST" action="../keyword_profile_updated_admin_6/index.php?<?php echo($row_CurrentAgent['UserID']); ?>">

And my checkboxes being displayed with:

//Display the checkbox
echo "<td width=\"2%\">";
echo "<input type=\"checkbox\" class=\"checkbox1 styled checkboxrowheight\"";
if (in_array($keyword['ActivityID'],$user_activities_it)) { echo " checked"; }
echo " name=\"ckbox[".$keyword['ActivityID']."]\" id=\"ckbox[".$keyword['ActivityID']."]\">";
echo "</td>\n";

The JS seems OK, as I have it working in a simple example with regular checkboxes - just not working in the example with the looped checkboxes.