Force user to select variant with Shopify Lite?

I’m using the “embed on a website” feature on my products from Shopify Lite. The Buy button allows the user to add products to the cart without selecting variants. I reached out to support and they said there is no function to force a selection, and they offered up some javascript for me. It doesn’t work, and I’ve tried to modify it to make it work, but I don’t really know what I’m doing. Here’s the code from Shopify support:

document.querySelector('button[name="add"]').addEventListener('click', function(event) {
var selectElement = document.querySelector('select[name="id"]');
if ([selectElement.value](http://selectElement.value) === '') {
event.preventDefault();
alert('Please select a variant before adding to cart.');
}
});

Can anyone help with this? Thank you.