data-value="yourValue" to each button in Webflow's Element Settings for unique input correlation.data-value upon a click event.To add data attributes to buttons and set the corresponding input values through JavaScript in Webflow, you will follow these steps:
data-value="yourValue" to each button. Ensure that each button has a unique data-value that corresponds to the input value you want to set.
<script> tags in the Footer Code section. The code should look like the following:data-value.
<script>
document.addEventListener('DOMContentLoaded', () => {
const buttons = document.querySelectorAll('button[data-value]');
const inputField = document.getElementById('yourInputId');
buttons.forEach(button => {
button.addEventListener('click', () => {
const value = button.getAttribute('data-value');
if (inputField) {
inputField.value = value;
}
});
});
});
</script>
Add data-attributes to each button and use JavaScript to update the input field in your contact form when a button is clicked. Ensure each button has a unique data-value, and use event listeners to set the value of the input field identified by its unique ID. By following these steps, you'll pre-fill form values based on button clicks effectively within Webflow.