I see that variations of this question has been asked several times before but none of the solutions seem to work for me unfortunately. I'm still a beginner in JavaScript hence I'm not sure what's happening here to debug this properly and what exactly to read up in the documentation.
Basically, I want to access and store the selected value of a drop down list inside a change event handler.
In my current approach, I am able to output the change event inside the event handler. But I cannot seem to assign it to a global variable outside of it, which I require for some other parts in my code.
Here is my MWE:
let dd = document.getElementById('dropDownMenu')
let dropDownChoice;
dd.addEventListener('change', function(e){
dropDownChoice = e.target.value;
console.log(dropDownChoice); // This outputs the selected item whenever the drop down is changed
});
console.log(dropDownChoice) // This does not output anything