JQuery - getting all multibyte list values

I am trying to use jQuery to get all the values ​​that are in a multiple select box. I currently have a selection in which users are selected in the selection list and then added to the PickList field. I am trying to use jQuery to get a somewhat formatted list (formatted with spaces), so I can parse this list later. I can get a real weird string that is not formatted by doing this

$.map($('#PickList'), function(e) { return $(e).text(); } );

but it is not formatted with a space "" after each value, and the line looks like it has a ton of spaces in front of it or something like that. Does anyone know a way to do this? Thanks

+3
source share
4 answers

I would think that you want to get only the values ​​from the selected parameters.

var selected = $.map( $('#PickList option:selected'),
                      function(e) { return $(e).val(); } );
+8
source
var selectedOptions = $.map($('#PickList :selected'),
       function(e) { return $(e).text(); } );
var str = selectedOptions.join(' ');

If you want all the options, replace :selectedwith option.

Without it, you select only the element, so it is just like $('#PickList').text()

+6
source

This plugin can help you, it adds free helpers for most forms operations:

$("#PickList").selectedValues();

// Also available:
$("#PickList").isSelected("one", "two", "three");
$("#PickList").firstSelectedItem();
$("#PickList").lastSelectedItem();
0
source

try it

var multipleValues = $("#multiple").val() || [];
-1
source

Source: https://habr.com/ru/post/1721985/


All Articles