data-option
attributes.data-option
attributes.To show or hide divs based on a user's form selection in Webflow, you'll need to use Webflow Interactions or a bit of custom JavaScript for dynamic behavior.
div-option-a
, div-option-b
).data-option="A"
, data-option="B"
on your target divs to match with the form values.tag section and paste the following simplified script:
<script> document.addEventListener('DOMContentLoaded', function () { const selectField = document.querySelector('select[name="your-field-name"]'); // Replace with actual field name const optionDivs = document.querySelectorAll('[data-option]'); function updateDivs(selectedValue) { optionDivs.forEach(div => { if (div.getAttribute('data-option') === selectedValue) { div.style.display = 'block'; } else { div.style.display = 'none'; } }); } if (selectField) { updateDivs(selectField.value); // Initialize based on default selectField.addEventListener('change', function () { updateDivs(this.value); }); } });</script>
"your-field-name"
with the actual input field name.display: none
(in the Style panel) if you don’t want them visible on load.div.style.display
override.To show/hide divs based on a user's form selection in Webflow, create separate target divs for each option, tag them clearly (e.g., with data-option
), and use custom JavaScript to toggle their visibility based on the user's input value.