10 examples of 'how to set multiple select box values using jquery' in JavaScript

Every line of 'how to set multiple select box values using jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
255private updateDom_select(element: JQuery<HTMLElement>, value: any) {
256 element.val(value);
257}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

64function setMultipleSelectOptions(nextSelectedIndex) {
65 set(_state => {
66 const selectedOptionsArray = _state.selectedOptions.slice();
67
68 if (selectedOptionsArray.includes(nextSelectedIndex)) {
69 const index = selectedOptionsArray.indexOf(nextSelectedIndex);
70 selectedOptionsArray.splice(index, 1);
71 } else {
72 selectedOptionsArray.push(nextSelectedIndex);
73 }
74
75 return {
76 ..._state,
77 isPopoverOpen: true,
78 activeOption: nextSelectedIndex,
79 selectedOptions: selectedOptionsArray,
80 };
81 });
82}
3function set(el, value) {
4 $(el).val(value);
5 $('#' + $(el).data("target")).val(value);
6
7}
83function getSelectValues() {
84 var checkedArray = []
85 document.querySelectorAll('#select:checked').forEach(e => {
86 checkedArray.push(e.value);
87 });
88 checkedArrayStr = checkedArray.toString();
89 return checkedArrayStr
90}
68function initSelect2(box) {
69 select2(box, {
70 placeholder: box.dataset.placeholder,
71 allowClear: true,
72 });
73}
234function multipleSelect(mode){
235 var element_id = parseInt($("#multipleSelectionTool").data('img_container_id').split("___")[1]);
236 $(".img_container").each(function(){
237 if(!$(this).hasClass("image_selected")){
238
239 // Update the session list
240 updateListSession($(this).attr("id"), "selected", "gallery")
241
242 if (mode=='all'
243 || (mode=='from' && $(this).attr('id').split("___")[1]>element_id)
244 || (mode=='to' && $(this).attr('id').split("___")[1]<element_id)) {
245 $(this).addClass("image_selected")
246 }
247 }
248
249 })
250}
53export async function selectOption(value: string, selectField: ElementFinder): Promise<void> {
54 return selectField.$(`option[value="${value}"`).click();
55}
197private updateDom(element: JQuery<HTMLElement>, value: any) {
198 let tag = element.prop('tagName');
199 switch (tag) {
200 case 'INPUT':
201 this.updateDom_input(element, value);
202 break;
203 case 'TEXTAREA':
204 this.updateDom_normal(element, value);
205 break;
206 case 'SELECT':
207 this.updateDom_select(element, value);
208 break;
209 default:
210 this.updateDom_normal(element, value);
211 }
212}
23function setValue(id, value, onChange) {
24 var $value = $('#' + id + '.value');
25 if ($value.attr('type') === 'checkbox') {
26 $value.prop('checked', value).change(function() {
27 onChange();
28 });
29 } else {
30 $value.val(value).change(function() {
31 if ($(this).attr('id') === 'license') {
32 if ($(this).val()) {
33 $('#check').button('enable');
34 } else {
35 $('#check').button('disable');
36 }
37 $('#checkResult').html();
38 }
39 onChange();
40 }).keyup(function() {
41 $(this).trigger('change');
42 });
43 }
44}
19function setValue(id, value, onChange) {
20 var $value = $('#' + id + '.value');
21 if ($value.attr('type') === 'checkbox') {
22 $value.prop('checked', value).change(function () {
23 onChange();
24 });
25 } else {
26 $value.val(value).on('change', function() {
27 onChange();
28 }).keyup(function() {
29 // Check that only numbers entered
30 if ($(this).hasClass('number')) {
31 var val = $(this).val();
32 if (val) {
33 var newVal = '';
34 for (var i = 0; i < val.length; i++) {
35 if ((val[i] >= '0' && val[i] <= '9') || val[i] === '-' || val[i] === '+' || val[i] === '.' || val[i] === ',') {
36 if (val[i] === '.' && convertComma === true) val[i] = ',';
37 if (val[i] === ',' && convertComma === false) val[i] = '.';
38 newVal += val[i];
39 }
40 }
41
42 if (val != newVal) {
43 $(this).val(newVal);
44 }
45 }
46 }
47 $(this).trigger('change');
48 });
49 }
50}

Related snippets