I kind of got stuck with this code here. I am trying to retrieve the option text.
HTML code
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
for(i=0; i<list.length; i++) { // assume list[i] contains different names
var name_options = $('<option>' + list[i] + '</option>');
$('#names').append(name_options);
}
/* I want to retrieve data when a particular option is selected. But this doesnt work*/
$('#names').click(function(){
var val = $(this).find(':selected').html();
});
});
</script>
</head>
<body>
<select id='names' class='combobox'>
!-- options for names go here -->
</select>
</body>
</html>
I was unable to retrieve the selected value. And hence i used $("#names") as my selector since $("#names option") does not work.
What am I doing wrong here?