Search code examples
jquerylistboxalert

retrieving items from a listbox using jQuery


I ma trying to retrieve the options selected from a listbox using jQuery. Here is the code.

$('#rt_select').click(function(e) {
            var selectedOpts = $('#source-listbox option:selected');

}

I know that selectedOpts is an object so how to fetch the values of the options selected from this Object?


Solution

  • Like this,

       str = "";
       $.each(selectedOpts, function (index, value) {
        str += value+" ";
       });
       alert(str);