From 784a315d85083a94212cc5644620b288c47dac44 Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Tue, 4 Jul 2023 19:55:37 +0200 Subject: [PATCH] ugly kludge to honor default selection in dropdown... --- script.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/script.js b/script.js index 6e37946..1b10eb5 100644 --- a/script.js +++ b/script.js @@ -117,18 +117,9 @@ const topicSelect = document.querySelector('#topic-select'); const topicChanged = function () { console.log('topic changed'); topic = topicSelect.selectedOptions[0].id; - redrawTable(); } -topicSelect.addEventListener("change", topicChanged); - -for (let x in topics) { - let option = document.createElement('option'); - option.id = x; - option.text = topics[x].title; - topicSelect.add(option); -} /** * Reads the seed from URL Parameter or generates new seed @@ -146,6 +137,20 @@ if (urlParams.has('topic')) { topic = 'tinder'; } +let index = 0; +for (let x in topics) { + let option = document.createElement('option'); + option.id = x; + option.text = topics[x].title; + topicSelect.add(option); + if (x === topic) { + topicSelect.selectedIndex = index; + }; + index++; +} + +topicSelect.addEventListener("change", topicChanged); + /** * Set fields, headline and center image based on topic */