The lists show name; the selection is kept as id. Move roles and watch both readouts.

getSelectedValues() - what the form submits
getSelectedItems() - the objects

jQuery PickList: Object Items

jqxPickList bound to objects: displayMember names the field the user sees, valueMember the field that selectedItems, val() and getSelectedValues() work with. The lists show role names; what the application saves is the role ids.

A live JavaScript/jQuery example of jqxPickList, the jQWidgets PickList component, with its complete source code below. It is one of 7 jqxPickList demos for jQuery.

jqxPickList API used in this demo

Source code

To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $.

The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxbuttons.js, jqxscrollbar.js, jqxlistbox.js, jqxpicklist.js.

It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).

script.js

$(document).ready(function () {
    // Roles as the server sends them. The user picks by name; the application reads
    // ids back - getSelectedValues() and val() return the valueMember field, and
    // getSelectedItems() returns the original objects.
    var roles = [
        { id: 'admin', name: 'Administrator' },
        { id: 'editor', name: 'Editor' },
        { id: 'author', name: 'Author' },
        { id: 'contributor', name: 'Contributor' },
        { id: 'subscriber', name: 'Subscriber' },
        { id: 'moderator', name: 'Moderator' },
        { id: 'billing', name: 'Billing manager' },
        { id: 'support', name: 'Support agent' }
    ];

    $('#jqxPickList').jqxPickList({
        width: 620,
        height: 320,
        source: roles,
        displayMember: 'name',
        valueMember: 'id',
        selectedItems: ['editor', 'contributor'],   // ids, not names
        sourceHeader: 'Available roles',
        targetHeader: 'Assigned roles'
    });

    var show = function () {
        var values = $('#jqxPickList').jqxPickList('getSelectedValues');
        var items = $('#jqxPickList').jqxPickList('getSelectedItems');
        $('#values').text(JSON.stringify({ userId: 4021, roles: values }, null, 2));
        $('#items').text(items.length ? items.map(function (r) { return r.name + '  (' + r.id + ')'; }).join('\n') : '(none)');
    };
    $('#jqxPickList').on('change', show);
    show();
});

body.html

<div id="content">
    
    <div class="demo">
        <p class="demo-hint">
            The lists show <code>name</code>; the selection is kept as <code>id</code>. Move roles and watch both readouts.
        </p>
        <div id="jqxPickList"></div>
        <div class="demo-out">
            <div>
                <strong>getSelectedValues() - what the form submits</strong>
                <code id="values"></code>
            </div>
            <div>
                <strong>getSelectedItems() - the objects</strong>
                <code id="items"></code>
            </div>
        </div>
    </div>
</div>

More jQuery PickList demos