this is my code and has a problem with the function. I don't know how to create a function that will look like in the second snippet.
var documents = ["docu1", "docu2", "docu3", "docu4"];
var sel = document.getElementById("input");
for (var i = 0; i < documents.length; i++) {
var opt = document.createElement('option');
opt.innerHTML = documents[i];
opt.value = documents[i];
sel.appendChild(opt);
}
function myFunction() {
var c = document.getElementById("input").value;
var a = documents.indexOf(c);
var newOptionDocuments = documents.splice(c, 1);
createNewSel(documents)
}
function createNewSel(documents) {
var select = document.createElement("select");
select.name = "cert";
select.id = i++;
document.getElementById("demo").appendChild(select);
for (const doc of documents) {
var option = document.createElement("option");
option.value = doc;
option.text = doc.charAt(0).toUpperCase() + doc.slice(1);
select.appendChild(option);
}
}
<button type="submit" onclick="myFunction()">Try it</button>
<select id="input">
</select>
<p id="demo"></p>
I want to create a "select" that will not repeat the same value and will update the option in all select when I click "try It" and will function like this.
```
-t0: select_0 > list { 1, 2, 3, 4 }
-t1: select_0 > choose [3] ( select_0 > list { 1, 2, [3], 4 }
-t2: click on TryIt
select_0 > list { 1, [3], 4 }
select_1 > list { [1], 2, 4 }
-t3: click on TryIt
select_0 > list { [3], 4 }
select_1 > list { [1], 4 }
select_2 > list { [2], 4 }
```
if we change
select_0 { [3], 4 } to { 3, [4] }
function()
select_1 > list { [1], 3 }
select_2 > list { [2], 3 }
-t4: click on TryIt
select_0 > list { [4] }
select_1 > list { [1] }
select_2 > list { [2] }
select_3 > list { [3] }
end;