Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

88
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!