var checkedGroups = 0; function monitorRadio() { document.querySelectorAll('input[type="radio"]').forEach(function (el) { el.addEventListener('change', incCounter, { once: true }); }); } function incCounter() { checkedGroups++; } function checkCount() { if (checkedGroups === 5) { countdown(); } } window.addEventListener("keydown", function (event) { if (event.defaultPrevented) { return; } checkCount(); switch (event.key) { case "a": checkedGroups++; getid = 'a'+checkedGroups; document.getElementById(getid).checked = true; checkCount(); break; case "b": checkedGroups++; getid = 'b'+checkedGroups; document.getElementById(getid).checked = true; checkCount(); break; default: checkCount(); return; } event.preventDefault(); }, true);