I have some arrays defined in js, I want to use the variable's value from selected option to select which array should I select.
I tried using this:
//code HTML
<select id="bank">
<option value="ACB">ACB</option>
<option value="SCB">SCB</option>
</select>
<select id="month">
<option value="1">1 month</option>
<option value="2">2 month</option>
<option value="3">3 month</option>
</select>
<p id="demo"></p>
// JS
var ACB = ["1%", "2%", "3%"];
var SCB = ["4%", "5%", "6%"];
selectElement = document.querySelector('#bank');
var a = selectElement.value; // a = ACB
selectElement = document.querySelector('#month');
var b = selectElement.value; // b = 1
document.getElementById("demo").innerHTML = a[b]; // I was hoping result is "1%"
Any suggestions are appreciated!
Thanks so much!