Here it's my html code
<select class="changeOption">
{% for dBoy in dBoyList %}
<option value="{{dBoy.id}}" data-locid='{{dboy.location.id}}'
{% endfor %}
</select>
When i'm select any option from dropdown list it shows undefine
JQuery code
$( ".changeOption" ).change(function() {
var locId = $(this).data("locid")
alert("id: "+locId);
});
this
refers to context of select element. you need to find selected option in it and then get the attribute:
$(".changeOption").change(function() {
var locId = $(this).find(':selected').data("locid")
alert("id: "+locId);
});
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