Get value of selected option



examples/dom/get_selected_option.html
<select id="id_of_select">
<option></option>
<option value="2">two</option>
<option value="3">three</option>
<option value="4">four</option>
</select>

<button id="btn">Show selected</button>

<div id="display"></div>

<script src="get_selected_option.js"></script>

examples/dom/get_selected_option.js
"use strict";

function show_selected() {
    var selector = document.getElementById('id_of_select');
    var value = selector[selector.selectedIndex].value;

    document.getElementById('display').innerHTML = value;
}

document.getElementById('btn').addEventListener('click', show_selected);;