Reputation: 105
I am trying to display the selected value from a dropdown menu using jquery. The options in the jquery are loaded dynamically.
for(i=0;i<data.length;i++){
$('.daysofWeek').append('<option>' + data[i].days +'</option');
}
Now Im trying to display the options selected using the following code.
$('.daysofWeek').on("change" ,function() {
var daySelected= $('.daysofWeek').children("option:selected").text();
alert(daySelected);
});
The problem is that the display returns the first value in the dropdown along with the value selected. For example, if the selected value were Monday it is returning SundayMonday. Please advice.
Upvotes: 0
Views: 54
Reputation: 1851
Take a look at this jsfiddle http://jsfiddle.net/7vbs9eov/
I just tried this.value
and it alerted the option I selected.
Maybe this will work for you?
Upvotes: 2