Skip to content
Advertisement

Two Drop Down Menus

I wish I could use jQuery, but this has to in JavaScript. I’d appreciate the help. When “empty” (first drop down menu) is selected, I need all values from the second drop down menu (a, b, c). When “1” is selected, I need just a, b. When “2” is selected, I need just b, c.

Nothing’s wrong with the drop down menu. Just had to change the values. How would I fix this in JavaScript?

First menu

JavaScript

Second menu

JavaScript

Advertisement

Answer

One solution that I would prefer is to set the style to none via CSS in JS. This way, the element still exists but it is just hidden from the viewer.

You can the get value of an element via [element-here].value and compare the to some value that you want. From there, you would select the second drop down option value you have and run [element-here].style.display = "none"

Another way that is more complicated that I would not recommend is to create and destroy elements entirely. Something like:

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