Skip to content
Advertisement

After the condition of a select is met, show or hide further selects

I have the following question because I haven’t found anything on the internet. I have created several selects with HTML. The select has the optiions yes / no. The first select checks whether the topic is relevant, if it is not relevant, then the remaining selects for the topic should disappear. I then send the evaluation of the selects with a button (evaluation with php), but would like to have the behavior, directly between the change from yes to no. I am open to all possibilities, be it CSS, HTML or JavaScript. In addition, all of my Selects are in a “div”

Advertisement

Answer

On your checkbox, you can add onchange="changeChk()" like this:

JavaScript

then in Javascript you can make disappear/appear other checkboxes in this function:

JavaScript

with a bit of css:

JavaScript

Example where I surround the checkbox with a span to make the label disappear as well:

JavaScript
JavaScript
JavaScript

If you have a select, it’s (almost) the same.

On your select, you can add onchange="changeValue()" then in Javascript you can make disappear/appear other selects.

Example:

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