get multiple values from dropdownlist in JavaScript

后端 未结 3 1951
醉酒成梦
醉酒成梦 2021-01-14 05:10

How can I get the values selected in the drop-down list, using a JavaScript function? User can select multiple values from both the elements. Following are the elements

3条回答
  •  逝去的感伤
    2021-01-14 05:51

    var fld = document.getElementById('icOptions');
    var values = [];
    for (var i = 0; i < fld.options.length; i++) {
      if (fld.options[i].selected) {
        values.push(fld.options[i].value);
      }
    }
    // do something with values
    

提交回复
热议问题