I'm trying to set the default options on a product on my Squarespace website.
I'm using the brine template.
Here is the website: https://pear-nectarine-6mdf.squarespace.com/childrens-subscription
password is: qpbooks
I'm injecting the following code into the page:
<script>
function setValue()
{
var dropdown = document.querySelectorAll('[data-variant-option-name="Back Binding"]')[0];
dropdown.value = 'Mixed';
Y.one('#'+dropdown.id).simulate('change');
var dropdown2 = document.querySelectorAll('[data-variant-option-name="Subscription Length"]')[0];
dropdown2.value = '12 Months';
Y.one('#'+dropdown2.id).simulate('change');
}
window.onload = setValue;
</script>
I get the following error when looking at the console:
38: Y.one('#'+dropdown.id).simulate('change');
childrens-subscription:38 Uncaught TypeError: Cannot read property 'simulate'
of null at setValue (childrens-subscription:38)
I think this means that YUI is not finding my selection box maybe?
When I remove the simulate calls the code runs without error and the text in the selection box changes but the product price doesn't.
I'm having trouble accessing the YUI library documentation. Any help would be much appreciated.
The
selectelements which you are referencing do not haveidproperties and, therefore, when you runY.one('#'+dropdown.id).simulate('change');you will get an error. There is noidondropdown.Instead, simply pass
dropdownintoY.one(...)like this:That should do it.