aboutsummaryrefslogtreecommitdiff
path: root/webAO/dom/getIndexFromSelect.ts
diff options
context:
space:
mode:
authorstonedDiscord <Tukz@gmx.de>2022-09-07 23:41:55 +0200
committerGitHub <noreply@github.com>2022-09-07 23:41:55 +0200
commit84cdbfff31c31eff9e7ba2a1d6c73f6d08ac5e43 (patch)
treefe9a18c8c0cdbf1ab8ef037af6f98a53b0ea018f /webAO/dom/getIndexFromSelect.ts
parent5362069a05b4bfbef03f37605af979aa3cf0e066 (diff)
parent3f8d0974b327e663328bc36cd97f1ba1855a2269 (diff)
Merge pull request #169 from caleb-mabry/evenMoreWindowFunctions
Added more functions
Diffstat (limited to 'webAO/dom/getIndexFromSelect.ts')
-rw-r--r--webAO/dom/getIndexFromSelect.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/webAO/dom/getIndexFromSelect.ts b/webAO/dom/getIndexFromSelect.ts
new file mode 100644
index 0000000..2f21653
--- /dev/null
+++ b/webAO/dom/getIndexFromSelect.ts
@@ -0,0 +1,16 @@
+/**
+ * Find index of anything in select box.
+ * @param {string} select_box the select element name
+ * @param {string} value the value that need to be compared
+ */
+export function getIndexFromSelect(select_box: string, value: string) {
+ // Find if icon alraedy existed in select box
+ const select_element = <HTMLSelectElement>document.getElementById(select_box);
+ for (let i = 1; i < select_element.length; ++i) {
+ if (select_element.options[i].value === value) {
+ return i;
+ }
+ }
+ return 0;
+}
+window.getIndexFromSelect = getIndexFromSelect; \ No newline at end of file