Use javascript to simulate a click on Ecommerce variant select option

I am trying to use checkboxes to select an option in an HTML select element. I have it NEARLY working and a working demo can be seen here - ADDONS Soundary - if you tick the checkboxes marked “Cycling Clips” or “Red Safety Light” - you can see that the faded out select boxs above change.

However, the price should change and when the item is added to cart, these “Add-ons” should be included - but they are not. If you select the dropdowns manually using your mouse, you will see how it should work.

A simplified version of the javascript I am using is:

$("select :nth-child(2)").prop('selected', true).trigger('change');

Is there a way to simulate a click that will work in this instance?

I found this piece of code on another thread and it worked when a jquery trigger or click would not work. However, I 've tried this and it didn’t work either.

$(function() {
    $('a').click(function() {
        // 'this' is not a jQuery object, so it will use
        // the default click() function
        this.click();
    }).click();
});

Any help is greatly appreciated!


Previous thread with cloneable example - Choose variant with checkbox (Jquery)

1 Like

Solved in this thread

2 Likes

Thanks for updating! Unfortunately, the read-only link no longer works. Are you able to update it? I’m working on something similar and would really appreciate it! Thank you.

I never got this working properly. If it’s anywhere, its at [this link].(Choose variant with checkbox (Jquery) - #11 by Diarmuid_Sexton)