I'm very new to using Typescript/Javascript, but so far no information I found on the internet has helped me with my problem. I'm trying to swap the option values of two select elements, so that the elements will be seen with swapped values on the HTML website as well as have their values swapped in the Typescript file to work with them.
Here is what the select elements look like in my HTML file:
<div class="bigtext">Currency 1:</div>
<div class="smalltext">Your input currency</div>
<select id="select1">
<option></option>
<option>EUR</option>
<option>USD</option>
</select>
<div class="bigtext">Currency 2:</div>
<div class="smalltext">The currency you want to convert to</div>
<select id="select2">
<option></option>
<option>EUR</option>
<option>USD</option>
</select>
This is inside a form tag. The function that's supposed to swap the elements' values looks like this (in Javascript):
let currency1 = "";
let currency2 = "";
document.getElementById("select1").addEventListener("change", event => {
currency1 = document.getElementById("select1")[0].value;
});
document.getElementById("select2").addEventListener("change", event => {
currency2 = document.getElementById("select2")[0].value;
});
function swapCurrencies() {
let helper = currency1;
let htmlhelper = document.getElementById("select1")[0].value;
currency1 = currency2;
document.getElementById("select1")[0].value = document.getElementById("select2")[0].value;
currency2 = helper;
document.getElementById("select2")[0].value = htmlhelper;
}
There are probably a lot of stylistic inaccuracies here, but for now I'd really just be happy to know why it's not working the way I want it to. When I click the button on my HTML page, absolutely nothing happens.
Thanks in advance!