How do I use a list of one table to add entries to another table?

How do I use a list of one table to add entries to another table?

  
I have three tables:  Machines, MachineGroups, and MachineGroupMembers.  The MachineGroupMembers table looks like:

Id,MachineId,MachineGroupId

Both of the last two columns are foreign keys that point to Ids in the Machines and MachineGroups tables.

On the MachineGroup_Show web page, I would like to be able to display all of the machines from the Machines table and have the search bar to filter the results.  I would like to have a checkbox that will allow me to select the machines I want and add their Id and the current MachineGroups Id to the Machine.  I would like to add a button that will allow the user to add the selected machines to the MachineGroupMembers table with the Id of the current MachineGroup_Show page.

How do I go about doing that?

Thx.

Craig