From 74262c6381d2c12cdeba87739812b15de746c131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Fri, 27 Jan 2023 02:15:01 +0100 Subject: [PATCH] web: improve part update reselection --- public/index.html | 2 +- public/partdb.js | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/public/index.html b/public/index.html index 79a9b41..d97fc99 100644 --- a/public/index.html +++ b/public/index.html @@ -16,7 +16,7 @@

- +
diff --git a/public/partdb.js b/public/partdb.js index 3cb43e8..f9f4471 100644 --- a/public/partdb.js +++ b/public/partdb.js @@ -34,14 +34,23 @@ function search() function results() { - const select = document.getElementById('results'); - select.innerHTML = null; + const results = document.getElementById('results'); + let part_id = -1; + if (results.selectedIndex >= 0) { + part_id = parseInt(results.options[results.selectedIndex].value); + } + results.innerHTML = null; for (const part of parts) { const option = document.createElement('option'); option.setAttribute('value', part.id); option.innerHTML = part.name + " (" + part.description + ")"; - select.appendChild(option); + if (part_id == part.id) { + console.log(part_id); + option.selected = "selected"; + } + results.appendChild(option); } + select_part(); // in case we reselected } function clear() @@ -71,7 +80,7 @@ function clear() attachments.innerHTML = null; } -function select() +function select_part() { const results = document.getElementById('results'); if (results.selectedIndex >= 0) {