Conditionally Hide/Show Form Fields
How to hide or show certain form fields for input based on a specific field value selection


The JS
Create two variables, one that determines which fields to display on load, and the other for which fields to display on the field's value selection. We create an argument for each possible value.
We create two functions, one that will hide the specified fields for us, and the other to show the specified fields.
For each of our form views where the selection occurs, we create a handler with an event listener for a change in the field value that determines which fields show or hide.
On an Edit form specifically, we add an if statement to check if the field already has a value and show the appropriate fields based on the existing value.
The CSS
None needed 😎
How to Implement
For the variable arguments, you will need to adjust to your specific Field Names, Field ID's and Field Values
For each of the handlers, you will also need to adjust to your specific View ID's and Field ID's
Lastly, if using an edit form, you can update the variable name for the if statement to be something more generic or more specific for your use case.
to
for all 3 references to it in the if statement
Last updated
Was this helpful?