function updateField(checkboxNames, fieldName) { // Fetch all checkboxes corresponding to a given field var checkboxes = document.getElementsByName(checkboxNames); var checks = []; for (var box of checkboxes) { if (box.checked) { checks.push(box.value); } } // Update the field value with all checked box values const fieldEl = document.getElementById(fieldName); fieldEl.value = checks.join(); }