Answers for "multiselect selected values"

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

Browse Popular Code Answers by Language