Jump to content

Dropdown box value is not updating when changed using jQuery

Go to solution Solved by mcbowen,

Recommended Posts

Site URL: https://pigeon-eagle-lfzb.squarespace.com/store-1/p/style-01-hs2wj-rec4m-3dpak

Password = 123


When I try to change the value set in a select element using jQuery the value does not display on the screen, the selected attribute is added in HTML and when clicking on the dropdown the correct value is highlighted.

This is what displays:


This is what I am expecting:


The correct value is highlighted when clicking on the dropdown:


I have the following code which is not working on the Squarespace site:

<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
  $(document).ready(function() {
    $('select[data-variant-option-name=Color] option[value=Purple]').attr('selected', 'selected');

I've copied the except HTML and jQuery into jsfiddle and it seems to work there:


I have also tried using .val and .props but this does not fix it.


I have since tried adding a dropdown box on the home page and this works correctly so there must be something on the product page which is causing the issue.

I have a few more updates on this (Still not working):

Ive manaaged to get the dropbown box to visually update by setting the data-text attribute:

$("div.variant-select-wrapper.color-wrapper").attr("data-text", "white");

Looking at the HTML code I have noticed the following:


This does not change when using jQuery, it only changes when I manually click on a dropdown box and select it.

There is also a new attribute data-selected-variant that gets added when both colour and size are selected:


and also:



Edited by mcbowen
Link to comment
  • mcbowen changed the title to Dropdown box value is not updating when changed using jQuery
  • Replies 1
  • Views 3.8k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Create an account or sign in to comment

You need to be a member in order to leave a comment

  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.