I put all select tags in an array to iterate afterwards
var selects = document.getElementsByTagName("select");
I say that when select changes the value, call the following function
selects[i].onchange = function(e) {
Save the current value of select separately only for clarity, as it did not need, since the rest is in the same scope
var val = this.value;
Now I search in all selects if any already has the same value that was selected now
for (var z = 0; z < selects.length; z++) {
Here I need the position of the current select, because you need the check to occur in others
var index = Array.prototype.indexOf.call(selects, this);
Here I check if it is not the current select and if the selected value is equal to the current one
if ((z !== index) && selects[z].value === val) {
Now I will deselect the selected tag option
for (var o = 0; o < options.length; o++) {
if (options[o].selected) {
options[o].selected = false;
}
Here I select the first pattern again
(What is your holiday option?)
options[0].selected = true;
But only the first
<select>
is that disables options in others, the reverse does not happen ?– Isac
yes the reverse also happens, thank you for the reminder
– Music Lyrics HQ