Search results
let val, dom = '#your_selector_id'; val = $(dom+' option:selected').text(); console.log('Initial text is '+val); $(document).on('change', => { val = $(dom).select2('data').text; console.log('Selected text is '+val); }); Check your browser console for the debug print.
7 sie 2014 · To dynamically set the "selected" value of a Select2 component: Where the second parameter is an object with expected values. UPDATE: This does work, just wanted to note that in the new select2, "a_key" is "text" in a standard select2 object. so: {id: 100, text: 'Lorem Ipsum'}
There are two ways to programmatically access the current selection data: using .select2('data'), or by using a jQuery selector. Using the data method. Calling select2('data') will return a JavaScript array of objects representing the current selection.
Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and pagination (infinite scrolling) of results.
Input types affected: text, select-one, select-multiple. Usage: The text that is shown when a user has inputted a new item but has not pressed the enter key. To access the current input value, pass a function with a value argument (see the default config for an example), otherwise pass a string.
Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and pagination (infinite scrolling) of results.
You can get the text value of the currently selected item by: $('#id').select2('data').text