From 07a34b1b1297eb3ff11ae07d40ba5fd4dbb0880a Mon Sep 17 00:00:00 2001 From: gpkvt Date: Mon, 5 Jun 2023 10:31:28 +0200 Subject: [PATCH] Moved code into function --- static/js/shortcut.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/static/js/shortcut.js b/static/js/shortcut.js index abece38..e1bf225 100644 --- a/static/js/shortcut.js +++ b/static/js/shortcut.js @@ -29,6 +29,14 @@ function checkCount() { return false; } +function check(choice) { + value = checkedGroups[0]; + removeId(); + getid = choice+value; + document.getElementById(getid).checked = true; + checkCount(); +} + window.addEventListener("keydown", function (event) { if (event.defaultPrevented) { return; @@ -40,18 +48,10 @@ window.addEventListener("keydown", function (event) { switch (event.key) { case "a": - value = checkedGroups[0]; - removeId(); - getid = 'a'+value; - document.getElementById(getid).checked = true; - checkCount(); + check("a"); break; case "b": - value = checkedGroups[0]; - removeId(); - getid = 'b'+value; - document.getElementById(getid).checked = true; - checkCount(); + check("b"); break; default: checkCount();