I have some check boxes dynamically generated from php, and I'd like to be able to have a link to "select them all".

This is what I have so far:

within my body tag:
function checkAll(field)
for (i = 0; i < field.length; i++)
field[i].checked = true ;
// End -->

the form name is "categories" and the checkboxes look like this:

<input type=\"checkbox\" name=\"cat[]\" value=\"$row[catid]\" class=\"form\">

and my link to select them all look like this:

<a href=\"#\" onClick=\"checkAll('document.categories.cat[]')\">Select All</a>

right now, whenever I click the link, I get the error 'undefined' is null or not an object.

Any clues what's wrong?