jQuery UI Widgets Forums Lists ListBox how to get the list of all selected items

This topic contains 1 reply, has 2 voices, and was last updated by  Peter Stoev 12 years, 12 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author

  • ramya
    Member

    I am using the jqxListBox control to select multiple items. But I need a way to be able to get the values chosen on the fly. Whenever a user chooses an item or unselects an item, I want to show a string with the selected items. How can I achieve this?

    $(“#upgComp”).jqxListBox({multiple: true});
    $(‘#upgComp’).bind(‘select’, function (event) {
    var args = event.args;
    var item = $(‘#upgComp’).jqxListBox(‘getItem’, args.index);
    // alert(‘Selected: ‘ + item.label);
    });


    Peter Stoev
    Keymaster

    Hi ramya,

    To get a list of the selected items, you can do this:

    // get all items.
    var items = $("#jqxWidget").jqxListBox('getItems');
    // get selected indexes.
    var selectedIndexes = $("#jqxWidget").jqxListBox('selectedIndexes');
    var selectedItems = [];
    // get selected items.
    for (var index in selectedIndexes) {
    if (selectedIndexes[index] != -1) {
    selectedItems[index] = items[index];
    }
    }

    Hope this helps you.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.