.selectedIndex to the desired default, and dispatch a 'change' event. To set a default option for a select dropdown (e.g., product variant selector) in Webflow E-commerce, use basic JavaScript to manipulate the DOM once the page or CMS content loads.
<select> tag.
Example: You might find a class like .w-commerce-commercevariantoption.
You can use basic JavaScript code like:
querySelector or getElementById to target the dropdown..selectedIndex or set the selected attribute on a specific <option>.
Example Script (include in the Page Settings or an Embed block at the bottom of Body):
<script>
document.addEventListener("DOMContentLoaded", function () {
var dropdown = document.querySelector('.your-dropdown-class'); // Replace with actual class
if (dropdown) {
dropdown.selectedIndex = 1; // 0 is the first option, so use 1 for the second, and so on
dropdown.dispatchEvent(new Event('change')); // Trigger change to update variant selection
}
});
</script>
.your-dropdown-class with your actual dropdown class (e.g., .w-commerce-commercevariantoption).selectedIndex to the position of the option you want as default.
<script> tag at the bottom of the page’s body.
Use JavaScript to set .selectedIndex or .selected on the dropdown's <option> element and dispatch a change event to ensure Webflow's E-commerce system recognizes the selection. Always test on the published site for expected behavior.