aboutsummaryrefslogtreecommitdiff
path: root/webAO/dom/getIndexFromSelect.ts
blob: dbbdd2b2e5dfce8510f0f43d9b9bcb4f072474ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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;