HTML
<select id="country" >
<option value=""></option>
<option value="india">India</option>
<option value="australia">Australia</option>
<option value="turkey">Turkey</option>
</select>
JS
var a = document.getElementById('country');
b.addEventListener('select',function () {alert(this.value);} ,false);
I want to show the selected value in an alert box when the user selects an option from the list.
Use
change
event asselect
event is invoked when some text is selected in an element.
var a = document.getElementById('country');
a.addEventListener('change', function() {
alert(this.value);
}, false);
<select id="country">
<option value="" disabled selected>Please select your country</option>
<option value="India">India</option>
<option value="Australia">Australia</option>
<option value="Turkey">Turkey</option>
</select>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With