I can only get the last selected value on my select multiple dropdown.
I have tried answers on the forum but no luck.
My HTML:
<select id="provider" class="validate" multiple required>
<option value="" disabled>Invoice Provider Name</option>
<option>Provider 1</option>
<option>Provider 2</option>
</select>
My JS:
function addRow(){
var x=document.getElementById("provider");
var pro = '';
for (var i = 0; i < x.options.length; i++) {
if(x.options[i].selected ==true){
pro = x.options[i].length.value;
}
}
}
assuming that I selected Provider 1, Provider 2 on the dropdown, I want to get
Provider 1
Provider 2
Thank you.