Reputation: 197
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.
Upvotes: 13
Views: 34425
Reputation: 36599
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>
Upvotes: 29