How to get the selected value from a dropdown list (select) in JavaScript?
Hello everyone! I'm new to JavaScript and ran into a problem. I have a regular dropdown list (select) on an HTML page. I want to output its value to the console when an item is selected from the list. But I can't get it to work.
Here's my HTML code:
```html
```
And my JavaScript:
```javascript
function getValue() {
let select = document.getElementById('mySelect');
console.log(select.value);
}
```
When I click the button, `undefined` is printed to the console. I tried different options: `select.options[select.selectedIndex].value`, `sel
No answers yet.
Log in to leave an answer
Blogs