Skip to content
Advertisement

How do I toggle between displaying and hiding an element depending on a value selected from a drop down?

I am new to dev and am working on a little project of creating a worshipper counter app for my local mosque.

When the page loads, I want to show only the h1 and the drop down menu. Once an option selected, I want the counter app to display. I have written the function that will toggle the display using an onchange event. However, this is toggling between displaying and hiding no matter the option selected. I can’t seem to find how to display the counter when any value is selected from the dropdown. Please can someone point me in the right direction?

JavaScript
JavaScript
JavaScript

Many thanks in advance! 🙂

Advertisement

Answer

You can take advantage of your “empty” option in the select so that display() can detect that:

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement