i have two options lists
First list
- 0xmohamed
- aaaaaaaaaaa
test
<select id="0" multiple="" size="6"> <option value="0xmohamed">0xmohamed</option> <option value="aaaaaaaaaaa">aaaaaaaaaaa</option> <option value="test">test</option></select>
Second list
- aaaaaaaaaaa
test
<select id="5" name="ary[]" multiple="" size="6"> <option value="aaaaaaaaaaa">aaaaaaaaaaa</option> <option value="test">test</option> </select>
I want to check if value existe in the second list, if yes, remove it from the first list
I tried with this function
var e = document.getElementById('0');
var f = document.getElementById('5');
var output = [];
for(var a= e.options.length-1; a >= 0; a--) {
output.push(e.options[a].value);
}
console.log(output);
for(var b= f.options.length-1; b >= 0; b--) {
if (output.includes(f.options[b].value)){
var i=output.indexOf(f.options[b].value);
console.log(i);
e.remove(i);
}}
but, it work with one item in the list but not two or more, it remove different option from the first list and i think that's because when an item removed then after second loop, the items in the first list will have different indexes...maybe not sure
Hope someone can help