In Webflow, you can assign custom data-attributes to buttons using the Webflow Designer. Here's how you can achieve this and set the input value through JavaScript when a button is clicked:
In your JavaScript code, you can add an event listener to the buttons with the class name "custom-button". When one of these buttons is clicked, the function will be triggered, allowing you to set the input value based on the button's data-attribute. Here's an example code snippet:
```javascript
document.addEventListener("DOMContentLoaded", function() {
var buttons = document.querySelectorAll(".custom-button");
var inputElement = document.querySelector(".contact-input");
buttons.forEach(function(button) {
button.addEventListener("click", function() {
var buttonValue = button.getAttribute("data-value");
inputElement.value = buttonValue;
});
});
});
```
Make sure to replace ".custom-button" with the actual class name you used for your buttons and ".contact-input" with the class name of your contact form input. The code above fetches the data-value attribute of the clicked button and sets it as the value of the specified input element.
That's it! Now, when a user clicks one of the buttons, the corresponding data-value will be set as the value of the contact form input field. You can adjust this technique to accommodate different scenarios or requirements within your project.