Reputation: 6514
i have a div and i do append a drop-down to it. everything is fine but when i tried to get selected value of that drop-down, i get error on browser console "Cannot read property 'undefined' of undefined' " .
code :
var selected_index_book = document.getElementById("surah_selection");
var book_sel = selected_index_book.options[selected_index_book.selectedIndex].value;
var book_option_id=$('option:selected', $('#surah_selection')).index();
Upvotes: 2
Views: 98
Reputation: 14943
Use
var book_sel = $("#surah_selection option:selected").text();
var book_option_id = $("#surah_selection option:selected").attr('id');
Upvotes: 1