You want to assign a data attribute to buttons in Webflow and use JavaScript to set a form input’s value when a button is clicked. Here's how to do it step-by-step.
<script>
tag (in Page Settings, paste it in the Before body tag section):<script> document.addEventListener('DOMContentLoaded', function () { const buttons = document.querySelectorAll('[data-value]'); const input = document.getElementById('topic-input'); buttons.forEach(button => { button.addEventListener('click', function () { const value = this.getAttribute('data-value'); input.value = value; }); }); });</script>
data-value
attribute.Assign a data-value attribute to each button, give your form input a unique ID, and add simple JavaScript to listen for button clicks and populate the form. This ensures your form field is pre-filled with the appropriate value before submission.