# JS to Show/Hide Components Depending on Multiple Data Fields

> This snippet will show you how to display certain form components (all others are hidden) depending on special conditions.

Source: https://tadabase.com/docs/snippets/js-to-showhide-components-depending-on-multiple-data-fields  
Status: Not yet re-checked. Moved from our previous help site and not yet re-checked against the current product. Last edited Sep 20, 2024.

This snippet will show you how to display certain form components (all others are hidden) depending on special conditions.

**Step 1**

Add the class of “hide” as an “Additional CSS class” in all of the form component settings.

![Add CSS Class](https://community.tadabase.io/uploads/default/optimized/2X/4/4c635ce6ffcd6aeaba8345d6532998a0de6339a7_2_345x182.png)

**Step 2**

Add the JavaScript pasted below.

In the example below, the related components will only be shown for facility records which have a Facility Type of Healthcare and a specific category of "Surgery" or "Anesthetizing Location".

Replace the 'types' and 'categories' shown below (Healthcare, Surgery, Anesthetizing Location) with information from your app.

```
var DETAIL_COMPONENT_ID = "Component_ID";
var FACILITY_TYPE = "field_id";
var SPECIAL_CONDITION = "field_id";
var COMPONENT_TO_SHOW = "Component_ID";

TB.render(DETAIL_COMPONENT_ID, function(data) {
if(data.record[FACILITY_TYPE] === "Healthcare"){
if(data.record[SPECIAL_CONDITION] === "Surgery" && data.record[SPECIAL_CONDITION] === "Anesthetizing Location"){
TB.showComponent(COMPONENT_TO_SHOW);
}
}
});
```

**Replace the Component IDs in the code with the IDs of your component.**

![Screenshot for “JS to Show/Hide Components Depending on Multiple Data Fields”](https://tadabase-docs-assets.s3.amazonaws.com/uploads/images/gallery/2022-09/scaled-1680-/image-1663124076359.png)

**Replace the Field Slugs in the code with the Slugs of your fields.**

![Screenshot for “JS to Show/Hide Components Depending on Multiple Data Fields”](https://tadabase-docs-assets.s3.amazonaws.com/uploads/images/gallery/2022-09/scaled-1680-/image-(5).png)

**Original Community Post:**

[https://community.tadabase.io/t/js-to-show-hide-components-depending-on-multiple-data-fields/2105](https://community.tadabase.io/t/js-to-show-hide-components-depending-on-multiple-data-fields/2105)
