0
I am trying to make a list work, that if an option in the first "select box" is selected, the other "select box" appears. But it’s not working.
At first the codes are right. Can anyone tell me what’s going on?
Follows the code
First Select Box:
<select id="eassociado" name="eassociado" required>
<option disabled selected value> -- Selecione uma opção -- </option>
<option class="lista">ABRAPP</option>
<option class="lista">ABAAI</option>
<option class="lista">IBGC</option>
<option class="lista">ABRACAM</option>
<option class="lista">ABBC</option>
</select>
Second Select Box
<select name="ingresso" id="chkveg" required>
<option class="associadoEntidade" value="https://pag.ae/7ULKQLB9m">Associados Entidades Apoiadoras + C.Dados = R$940,00</option>
<option class="associadoEntidade" value="https://pag.ae/7ULKQZk-m">Associados Entidades Apoiadoras Normal = R$1.125,00</option>
</select>
Javascript:
var lista = document.querySelectorAll(".lista");
var associadoEntidade = document.querySelectorAll(".associadoEntidade");
console.log(associadoEntidade);
for(var i = 0; i < associadoEntidade.length; i++){
associadoEntidade[i].style.display = "none";
}
if (lista.selected==true){
associadoEntidade[i].style.display = "block";
}
hi buddy, thank you very much for the answer, but not quite what I need, I would like that when IBGC(for example) is selected in the first droplist, the Associate Entities Support.... that is in the second field appeared. And so with others, understand?
– Chead
I understood, but, what would be the relation of this, because in the first select has 6 options and the second has 2, what would be the relationship?
– LeAndrade
I put only 2 here to better understand, but in my code there are more
– Chead
I edited the answer, making a basic example, doing each check.
– LeAndrade
is about that, but as I hide one or more option from the second select?
– Chead
Face then you don’t want a select, ever seen some select with only one option??!
– LeAndrade
want like this, (for example) if I select ABRAPP, hide Associates Supporting Entities Normal = R$1.125,00, I know I have to put something inside the if of your code, but I don’t know what to do
– Chead
You have tried several times to explain what you want and I understand less and less, up there in the question you say that if an option in the first "select box" is selected, the other "select box" appears such an option now you already want me to hide. Not buying what you really want to do.
– LeAndrade
yes, I rephrased the question in a slightly wrong way, but for example that you wrote, I saw that it is easier to hide using some code inside that if
– Chead
tried if(chosen == 1) { chkveg.style.display = 'inline-block'; var a = chkveg.selectedIndex = 1; a.style.display = 'None'; } , but returns variable anonymity
– Chead
I think I understand what you wanted, I edited the answer.
– LeAndrade
Show, it worked, the code got huge, I think I could reduce a lot if I understood more of js, https://jsfiddle.net/ves2b5ag/1/
– Chead
It’s the right thing to do
for
and instead of taking the options by number pick by the for index. But that would make the code much more complex. However you can ask a new question with the code you already have and get help to decrease it.– LeAndrade
That code, it didn’t work on the iPad, you can tell me why?
– Chead