I'm writing a form with 4 <select>
elements. They all have the same options and I would like to disable, hide, or remove the selected option from one <select>
in the other <select>
elements with the same options in order to prevent the user to select the same option in multiple <select>
elements.
No jQuery, only plain JavaScript please.
If possible I would like the first option to always display in all <select>
elements:
<option class="select-items" selected>Sélectionnez..</option>
Here is the HTML for one <select>
:
<select class="custom-select mb-3" id="name_typage_0">
<option class="select-items" selected>Sélectionnez..</option>
<option class="select-items" value="designation">Désignation</option>
<option class="select-items" value="email">Email</option>
<option class="select-items" value="ville">Ville</option>
<option class="select-items" value="secteur_activite">Secteur d'activité</option>
</select>
Here is part of my JavaScript:
const custSelec = document.querySelectorAll('.custom-select');
custSelec.forEach(function(item){
item.addEventListener('change', function(){
if(item.options[item.selectedIndex].text == 'Sélectionnez..'){
count = -1;
}else{
count = 1;
total += count;
compteur.textContent = ` ${total}/${custSelec.length -1}`;