Select all checkbox

I have two checkboxes one with a value of '1' and the other a '0', I wrote a button in which it would select all of the checkboxes by changing the field to either a 1 or 0 accordingly. I am having two problems, one the loop I wrote in infinite but I feel as the code is right and it will add a new line when I want it to exit on last portal record. Second occasionally it will work but only if I click a field and than hit the button. I appreciate any help that I can get. Thank you.

A question, though: What does this "selection" indicate? Is it truly an attribute of the related record in the portal, or is it only true in the context of the parent table?

If the latter (which is a big if, but why I'm asking), you could have a field in the parent record for a list of "selected" keys from the related table. Then your checkbox could be a boolean based on whether the primary key in medcode is in the list field in the parent record (1 or 0) and the checkbox itself could be a button that adds or removes the key from the list stored in the parent table.

An advantage here would be that your "select all" button could just set parentTable::selectedList to list (medcode::primaryKey), and "deselect all" could just clear parentTable::selectedList.

It may be that "selected" really is an attribute of the table in the portal, though, in which case, pretend I didn't say anything.

A question, though: What does this "selection" indicate? Is it truly an attribute of the related record in the portal, or is it only true in the context of the parent table?

If the latter (which is a big if, but why I'm asking), you could have a field in the parent record for a list of "selected" keys from the related table. Then your checkbox could be a boolean based on whether the primary key in medcode is in the list field in the parent record (1 or 0) and the checkbox itself could be a button that adds or removes the key from the list stored in the parent table.

In that case one wouldn't even need a real field in the child table; just a flag icon with a Hide If condition of

IsEmpty ( FilterValues ( Parent::selectionList ; Child::id ) )

that does double-duty as a Set Field[] to add or remove the portal row ID from that list field.

“Finding” all selected children could then be a Go to Related Record [ matching only } via a relationship of