0
I have 3 dropdown’s with equal values (0.1, 2 and 3). Where 0 is 'Select a collaborator' 1 is 'Fábia' 2 is 'Helio' 3 is 'Sueli' I have to select a value on one dropdown and disappear from the others. Example: I select Sueli in the first Dropdown and has to disappear from the Second and Third, but in this second and third Fabio and Helio have to appear in the Second and Fabia and Helio in the Third. And when I select one of those names in the Second and Third you have to shape the 3 dropdowns according to that rule. One thing that also has to happen is when I select the item (value 0, 'Select a collaborator'), you have to go back to all the other dropdowns. I managed to do with Ifs but ta giant. The point is, I don’t know how to do For. I wanted a light. A help to learn. If anyone could help me, I’d really appreciate it. I did so:
function fnFuncao() {
var varField_idFacilitador1 = $("#varField_idFacilitador1 option:selected").val();
var varField_idFacilitador2 = $("#varField_idFacilitador2 option:selected").val();
var varField_idFacilitador3 = $("#varField_idFacilitador3 option:selected").val();
if (parseInt(varField_idFacilitador1) == parseInt(0)){
$("#varField_idFacilitador1 option[value='0']").show();
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador3 option[value='1']").show();
}
if (parseInt(varField_idFacilitador2) == parseInt(0)){
$("#varField_idFacilitador2 option[value='0']").show();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador2 option[value='2']").show();
$("#varField_idFacilitador3 option[value='2']").show();
}
if (parseInt(varField_idFacilitador3) == parseInt(0)){
$("#varField_idFacilitador3 option[value='0']").show();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='3']").show();
}
if (parseInt(varField_idFacilitador1) == parseInt(1)){
$("#varField_idFacilitador1 option[value='0']").show();
$("#varField_idFacilitador1 option[value="+varField_idFacilitador1+"]").show();
$("#varField_idFacilitador2 option[value="+varField_idFacilitador1+"]").hide();
$("#varField_idFacilitador3 option[value="+varField_idFacilitador1+"]").hide();
}
if(parseInt(varField_idFacilitador1) == parseInt(2)){
$("#varField_idFacilitador1 option[value='0']").show();
$("#varField_idFacilitador1 option[value="+varField_idFacilitador1+"]").show();
$("#varField_idFacilitador2 option[value="+varField_idFacilitador1+"]").hide();
$("#varField_idFacilitador3 option[value="+varField_idFacilitador1+"]").hide();
}
if(parseInt(varField_idFacilitador1) == parseInt(3)){
$("#varField_idFacilitador1 option[value='0']").show();
$("#varField_idFacilitador1 option[value="+varField_idFacilitador1+"]").show();
$("#varField_idFacilitador2 option[value="+varField_idFacilitador1+"]").hide();
$("#varField_idFacilitador3 option[value="+varField_idFacilitador1+"]").hide();
}
if (parseInt(varField_idFacilitador2) == parseInt(1)){
$("#varField_idFacilitador2 option[value='0']").show();
$("#varField_idFacilitador2 option[value="+varField_idFacilitador2+"]").show();
$("#varField_idFacilitador1 option[value="+varField_idFacilitador2+"]").hide();
$("#varField_idFacilitador3 option[value="+varField_idFacilitador2+"]").hide();
}
if(parseInt(varField_idFacilitador2) == parseInt(2)){
$("#varField_idFacilitador2 option[value='0']").show();
$("#varField_idFacilitador2 option[value="+varField_idFacilitador2+"]").show();
$("#varField_idFacilitador1 option[value="+varField_idFacilitador2+"]").hide();
$("#varField_idFacilitador3 option[value="+varField_idFacilitador2+"]").hide();
}
if(parseInt(varField_idFacilitador2) == parseInt(3)){
$("#varField_idFacilitador2 option[value='0']").show();
$("#varField_idFacilitador2 option[value="+varField_idFacilitador2+"]").show();
$("#varField_idFacilitador1 option[value="+varField_idFacilitador2+"]").hide();
$("#varField_idFacilitador3 option[value="+varField_idFacilitador2+"]").hide();
}
if (parseInt(varField_idFacilitador3) == parseInt(1)){
$("#varField_idFacilitador3 option[value='0']").show();
$("#varField_idFacilitador3 option[value="+varField_idFacilitador3+"]").show();
$("#varField_idFacilitador1 option[value="+varField_idFacilitador3+"]").hide();
$("#varField_idFacilitador2 option[value="+varField_idFacilitador3+"]").hide();
}
if(parseInt(varField_idFacilitador3) == parseInt(2)){
$("#varField_idFacilitador3 option[value='0']").show();
$("#varField_idFacilitador3 option[value="+varField_idFacilitador3+"]").show();
$("#varField_idFacilitador1 option[value="+varField_idFacilitador3+"]").hide();
$("#varField_idFacilitador2 option[value="+varField_idFacilitador3+"]").hide();
}
if(parseInt(varField_idFacilitador3) == parseInt(3)){
$("#varField_idFacilitador3 option[value='0']").show();
$("#varField_idFacilitador3 option[value="+varField_idFacilitador3+"]").show();
$("#varField_idFacilitador1 option[value="+varField_idFacilitador3+"]").hide();
$("#varField_idFacilitador2 option[value="+varField_idFacilitador3+"]").hide();
}
if (parseInt(varField_idFacilitador1) == parseInt(0) && parseInt(varField_idFacilitador2) == parseInt(0) && parseInt(varField_idFacilitador3) == parseInt(0)){
$("#varField_idFacilitador1 option[value='0']").show();
$("#varField_idFacilitador2 option[value='0']").show();
$("#varField_idFacilitador3 option[value='0']").show();
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador3 option[value='1']").show();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador2 option[value='2']").show();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='3']").show();
}
if (parseInt(varField_idFacilitador1) == parseInt(1) && parseInt(varField_idFacilitador2) == parseInt(0) && parseInt(varField_idFacilitador3) == parseInt(0)){
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador2 option[value='1']").hide();
$("#varField_idFacilitador3 option[value='1']").hide();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador2 option[value='2']").show();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='3']").show();
}
if (parseInt(varField_idFacilitador1) == parseInt(2) && parseInt(varField_idFacilitador2) == parseInt(0) && parseInt(varField_idFacilitador3) == parseInt(0)){
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador3 option[value='1']").show();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador2 option[value='2']").hide();
$("#varField_idFacilitador3 option[value='2']").hide();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='3']").show();
}
if (parseInt(varField_idFacilitador1) == parseInt(3) && parseInt(varField_idFacilitador2) == parseInt(0) && parseInt(varField_idFacilitador3) == parseInt(0)){
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador3 option[value='1']").show();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador2 option[value='2']").show();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='3']").hide();
$("#varField_idFacilitador3 option[value='3']").hide();
}
if (parseInt(varField_idFacilitador1) == parseInt(0) && parseInt(varField_idFacilitador2) == parseInt(1) && parseInt(varField_idFacilitador3) == parseInt(0)){
$("#varField_idFacilitador1 option[value='1']").hide();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador3 option[value='1']").hide();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador2 option[value='2']").show();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='3']").show();
}
if (parseInt(varField_idFacilitador1) == parseInt(0) && parseInt(varField_idFacilitador2) == parseInt(2) && parseInt(varField_idFacilitador3) == parseInt(0)){
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador3 option[value='1']").show();
$("#varField_idFacilitador1 option[value='2']").hide();
$("#varField_idFacilitador2 option[value='2']").show();
$("#varField_idFacilitador3 option[value='2']").hide();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='3']").show();
}
if (parseInt(varField_idFacilitador1) == parseInt(0) && parseInt(varField_idFacilitador2) == parseInt(3) && parseInt(varField_idFacilitador3) == parseInt(0)){
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador3 option[value='1']").show();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador2 option[value='2']").show();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador1 option[value='3']").hide();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='3']").hide();
}
if (parseInt(varField_idFacilitador1) == parseInt(0) && parseInt(varField_idFacilitador2) == parseInt(0) && parseInt(varField_idFacilitador3) == parseInt(1)){
$("#varField_idFacilitador1 option[value='1']").hide();
$("#varField_idFacilitador2 option[value='1']").hide();
$("#varField_idFacilitador3 option[value='1']").show();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador2 option[value='2']").show();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='3']").show();
}
if (parseInt(varField_idFacilitador1) == parseInt(0) && parseInt(varField_idFacilitador2) == parseInt(0) && parseInt(varField_idFacilitador3) == parseInt(2)){
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador3 option[value='1']").show();
$("#varField_idFacilitador1 option[value='2']").hide();
$("#varField_idFacilitador2 option[value='2']").hide();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='3']").show();
}
if (parseInt(varField_idFacilitador1) == parseInt(0) && parseInt(varField_idFacilitador2) == parseInt(0) && parseInt(varField_idFacilitador3) == parseInt(3)){
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador3 option[value='1']").show();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador2 option[value='2']").show();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador1 option[value='3']").hide();
$("#varField_idFacilitador2 option[value='3']").hide();
$("#varField_idFacilitador3 option[value='3']").show();
}
if (parseInt(varField_idFacilitador1) == parseInt(1) && parseInt(varField_idFacilitador2) == parseInt(0) && parseInt(varField_idFacilitador3) == parseInt(2)){
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador1 option[value='2']").hide();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='1']").hide();
$("#varField_idFacilitador2 option[value='2']").hide();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='1']").hide();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador3 option[value='3']").show();
}
if (parseInt(varField_idFacilitador1) == parseInt(1) && parseInt(varField_idFacilitador2) == parseInt(0) && parseInt(varField_idFacilitador3) == parseInt(2)){
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador1 option[value='2']").hide();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='1']").hide();
$("#varField_idFacilitador2 option[value='2']").hide();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='1']").hide();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador3 option[value='3']").show();
}
if (parseInt(varField_idFacilitador1) == parseInt(2) && parseInt(varField_idFacilitador2) == parseInt(3) && parseInt(varField_idFacilitador3) == parseInt(0)){
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador1 option[value='3']").hide();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador2 option[value='2']").hide();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='1']").show();
$("#varField_idFacilitador3 option[value='2']").hide();
$("#varField_idFacilitador3 option[value='3']").hide();
}
if (parseInt(varField_idFacilitador1) == parseInt(1) && parseInt(varField_idFacilitador2) == parseInt(3) && parseInt(varField_idFacilitador3) == parseInt(0)){
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador1 option[value='3']").hide();
$("#varField_idFacilitador2 option[value='1']").hide();
$("#varField_idFacilitador2 option[value='2']").show();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='1']").hide();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador3 option[value='3']").hide();
}
if (parseInt(varField_idFacilitador1) == parseInt(2) && parseInt(varField_idFacilitador2) == parseInt(0) && parseInt(varField_idFacilitador3) == parseInt(1)){
$("#varField_idFacilitador1 option[value='1']").hide();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='1']").hide();
$("#varField_idFacilitador2 option[value='2']").hide();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='1']").show();
$("#varField_idFacilitador3 option[value='2']").hide();
$("#varField_idFacilitador3 option[value='3']").show();
}
if (parseInt(varField_idFacilitador1) == parseInt(0) && parseInt(varField_idFacilitador2) == parseInt(3) && parseInt(varField_idFacilitador3) == parseInt(1)){
$("#varField_idFacilitador1 option[value='1']").hide();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador1 option[value='3']").hide();
$("#varField_idFacilitador2 option[value='1']").hide();
$("#varField_idFacilitador2 option[value='2']").show();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='1']").show();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador3 option[value='3']").hide();
}
if (parseInt(varField_idFacilitador1) == parseInt(0) && parseInt(varField_idFacilitador2) == parseInt(1) && parseInt(varField_idFacilitador3) == parseInt(3)){
$("#varField_idFacilitador1 option[value='1']").hide();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador1 option[value='3']").hide();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador2 option[value='2']").show();
$("#varField_idFacilitador2 option[value='3']").hide();
$("#varField_idFacilitador3 option[value='1']").hide();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador3 option[value='3']").show();
}
if (parseInt(varField_idFacilitador1) == parseInt(0) && parseInt(varField_idFacilitador2) == parseInt(1) && parseInt(varField_idFacilitador3) == parseInt(2)){
$("#varField_idFacilitador1 option[value='1']").hide();
$("#varField_idFacilitador1 option[value='2']").hide();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador2 option[value='2']").hide();
$("#varField_idFacilitador2 option[value='3']").show();
$("#varField_idFacilitador3 option[value='1']").hide();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador3 option[value='3']").show();
}
if (parseInt(varField_idFacilitador1) == parseInt(3) && parseInt(varField_idFacilitador2) == parseInt(2) && parseInt(varField_idFacilitador3) == parseInt(0)){
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador1 option[value='2']").hide();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador2 option[value='2']").show();
$("#varField_idFacilitador2 option[value='3']").hide();
$("#varField_idFacilitador3 option[value='1']").show();
$("#varField_idFacilitador3 option[value='2']").hide();
$("#varField_idFacilitador3 option[value='3']").hide();
}
if (parseInt(varField_idFacilitador1) == parseInt(3) && parseInt(varField_idFacilitador2) == parseInt(1) && parseInt(varField_idFacilitador3) == parseInt(0)){
$("#varField_idFacilitador1 option[value='1']").hide();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador2 option[value='2']").show();
$("#varField_idFacilitador2 option[value='3']").hide();
$("#varField_idFacilitador3 option[value='1']").hide();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador3 option[value='3']").hide();
}
if (parseInt(varField_idFacilitador1) == parseInt(2) && parseInt(varField_idFacilitador2) == parseInt(0) && parseInt(varField_idFacilitador3) == parseInt(3)){
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador1 option[value='2']").show();
$("#varField_idFacilitador1 option[value='3']").hide();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador2 option[value='2']").hide();
$("#varField_idFacilitador2 option[value='3']").hide();
$("#varField_idFacilitador3 option[value='1']").show();
$("#varField_idFacilitador3 option[value='2']").hide();
$("#varField_idFacilitador3 option[value='3']").show();
}
if (parseInt(varField_idFacilitador1) == parseInt(3) && parseInt(varField_idFacilitador2) == parseInt(0) && parseInt(varField_idFacilitador3) == parseInt(2)){
$("#varField_idFacilitador1 option[value='1']").show();
$("#varField_idFacilitador1 option[value='2']").hide();
$("#varField_idFacilitador1 option[value='3']").show();
$("#varField_idFacilitador2 option[value='1']").show();
$("#varField_idFacilitador2 option[value='2']").hide();
$("#varField_idFacilitador2 option[value='3']").hide();
$("#varField_idFacilitador3 option[value='1']").show();
$("#varField_idFacilitador3 option[value='2']").show();
$("#varField_idFacilitador3 option[value='3']").hide();
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="varField_idFacilitador1" onChange="fnFuncao(this.value);">
<option value="0">Selecione o Colaborador 1</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select id="varField_idFacilitador2" onChange="fnFuncao(this.value);">
<option value="0">Selecione o Colaborador 2</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select id="varField_idFacilitador3" onChange="fnFuncao(this.value);">
<option value="0">Selecione o Colaborador 3</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
There is a way with less code and more dynamic to make this code?
– Carmona007
Edit the question and put HTML please.
– Laércio Lopes
Laercio o o Html são 3 Dropdowns com 3 valores iguais: Os Valores São: id Nome Nome do campo 1 Fábia varField_idFacilitador1 2 Helio varField_idFacilitador2 3 Sueli varField_idFacilitador3
– Carmona007
puts html bro ... pfvr
– Murilo Melo
what is this
option:selected
?– Murilo Melo
one more thing, why so many
if
? useselse if
– Murilo Melo
So that’s the question. I want to make a Loop to go through the values and go through it. But I can’t do it. option:Selected is Jquery. It’s how it treats <select option> Ja is in Html only on the JS/JQUERY part. varField_idFacilitador1 is the Dropdown 1 varField_idFacilitador2 is the Dropdown 2 varField_idFacilitador3 is the Droodown 3
– Carmona007
WE NEED HTML
– Bsalvo
I put the HTML
– Carmona007
I saw you use
.hide()
to hide a<option>
. The problem with this is that it doesn’t work in IE (it works in Chrome, I think Firefox tb and I didn’t test in Opera)... so it would be better to do as @bfavaretto proposed, instead of hiding, disable.. or else, if you make a point of hiding even without using.hide()
, an idea would be to create an array for each<select>
and each time an option is selected, dynamically recreate the<select>
pulling the values of your respective array, ignoring the value that is to ignore.– Sam
But IE here is not going to be a problem. And I’m hiding the value of Option because here it has to be like this. But in this case it would be composite array?
– Carmona007
Now they want four figures for Dropdown. Like, Fabia, Helio, Sueli, and Lucas. And as it comes from the database can have infinite records per dropdown.
– Carmona007
So far so good because this dynamic is coming from the bank. However I’m not able to return the values when you select option 0("select").
– Carmona007
@DVD Cara to perdidaço... And they put me against the wall here. Look where I got: https://jsfiddle.net/toewrmox/88/
– Carmona007