Looking to retrieve the name attribute of a selected option in Vuejs. After experimenting with the value attribute, I found that it worked successfully. Below is the code I used:
Tested code:
<select id="countryselect" name="country" @change="onChange()">
<option value="1" name="0">Afghanistan</option>
<option value="2" name="0">Albania</option>
<option value="3" name="0">Algeria</option>
<option value="4" name="1">Malaysia</option>
<option value="5" name="0">Maldives</option>
</select>
var app = new Vue({
el: '#app',
methods: {
onChange: function() {
// This works perfectly
var b = event.target.value;
// This does not work correctly
var c = event.target.name;
}
},
});
If you have any insights on how to achieve this, please share. Thank you.