Answers for "get array of selected options from select element"

1

get array of selected options from select element

var values = $('#select-meal-type').val();
Posted by: Guest on September-07-2020
0

get array of selected options from select element

function getSelectValues(select) {
  var result = [];
  var options = select && select.options;
  var opt;

  for (var i=0, iLen=options.length; i<iLen; i++) {
    opt = options[i];

    if (opt.selected) {
      result.push(opt.value || opt.text);
    }
  }
  return result;
}
Posted by: Guest on September-07-2020
0

javascript select multiple values

const selected = document.querySelectorAll('#select-meal-type option:checked');
const values = Array.from(selected).map(el => el.value);
Posted by: Guest on March-30-2020

Code answers related to "get array of selected options from select element"

Code answers related to "Javascript"

Browse Popular Code Answers by Language