var checkedGroups = [1,2,3,4,5]; var countdownActive = false; function monitorRadio() { document.querySelectorAll('input[type="radio"]').forEach(function (el) { el.addEventListener('change', removeId, { once: true }); }); } function removeId(e) { if (e) { value = e.target.id.charAt(1); } else { value = checkedGroups[0]; } checkedGroups = checkedGroups.filter(function(item) { return item != value; }) } function checkCount() { if (checkedGroups.length == 0) { if (countdownActive == false) { countdown(); } countdownActive = true; return true; } return false; } window.addEventListener("keydown", function (event) { if (event.defaultPrevented) { return; } if (checkCount()) { return; }; switch (event.key) { case "a": value = checkedGroups[0]; removeId(); getid = 'a'+value; document.getElementById(getid).checked = true; checkCount(); break; case "b": value = checkedGroups[0]; removeId(); getid = 'b'+value; document.getElementById(getid).checked = true; checkCount(); break; default: checkCount(); return; } event.preventDefault(); }, true);