Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

89
Visualizações
How to toggle visibility of a Div element based on change events from two different select form fields

I am trying to toggle the visibility of a div element based on the values from two different select form fields.

The HTML select form fields have ids: #team and #country respectively.

I have so far tried:

let teamVal;
 document.getElementById("team").addEventListener("change", function (e) {
   teamVal= e.target.value;
 });

 let countryVal;
 document.getElementById("country").addEventListener("change", function (e) {
   countryVal = e.target.value;
 });

// a helper function that should toggle the div element with an id, #myDiv
function toggleDivVisibility(teamVal, countryVal) {
  console.log("Toggle method called!");

  const myDiv = document.getElementById("myDiv");

  if (teamVal === "firmino" && countryVal === "brazil") {
    myDiv.style.display = "none";
  } else {
    myDiv.style.display = "block";
  }
}

toggleDivVisibility(teamVal, countryVal);

Thus far, the method seems to be called on document load, however the implementation doesn't work.

Any assistance will be highly appreciated.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda