does anyone know how to get the currently selected value from the select field? I have no idea how to do it, I tried many ways?
Asked
Active
Viewed 32 times
-2
-
1And... What did you try?! – Seabyte Feb 26 '23 at 19:20
-
Is this what you're looking for: `document.querySelector("#
").value` – Dima Feb 26 '23 at 19:22 -
@Seabyte It doesn't matter anyway since it doesn't work at all anyway. – Patryk Gmyrek Feb 26 '23 at 19:24
-
@Dima I want to be able to perform some operations on the child that would be currently selected in the selector. – Patryk Gmyrek Feb 26 '23 at 19:27
1 Answers
1
document.getElementById('myButton').addEventListener('click', function () {
console.log(document.getElementById('mySelect').value)
})
<select id="mySelect">
<option value="a">a</option>
<option value="b">b</option>
</select>
<button id="myButton" type="button">Show Selection</button>

Eric Fortis
- 16,372
- 6
- 41
- 62