change function not working with select2

Highlighted
Tourist
8 0 2

Hi, the code is working outside Shopify with the Select2 implementation, and it does work without the Select2 implementation when I put in Shopify. It seems like it doesn't notice the changes in the first select.

 


<script> var brandName $.getJSON("link", function(data) { brandName = Object.keys(data); var ele = document.getElementById('brand'); for (var i = 0; i < brandName.length; i++) { ele.innerHTML = ele.innerHTML + '<option value="' + brandName[i] + '">' + brandName[i].charAt(0).toUpperCase() + brandName[i].slice(1); + '</option>'; } console.log(document.getElementById('brand').value); }); $('#brand').change(function(){ var $dropdown = $(this); console.log($dropdown); $.getJSON("link", function(data) { var key = $dropdown.val(); var vals = []; vals = data[key].split(","); var $secondChoice = $("#car-model"); $secondChoice.empty(); $.each(vals, function(index, value) { $secondChoice.append("<option>" + value + "</option>"); }); }); }); </script>

 

0 Likes
Highlighted
Shopify Expert
3298 526 775

Hi @seatup 

Have you tried that select2 library working initial with your store?

like ass direct html and try  it if work then any issue with your code.

Want to modify or custom changes on store hire me.
If helpful then please Like and Accept Solution.
Email: jasoliyabrijesh123@gmail.com
Skype: jasoliya.brijesh
Want to get Free review and advice for sale on store ?? just text me here
0 Likes
Highlighted
Tourist
8 0 2

I solved wrapping the .change function inside "$(document).ready(function() {}" 

0 Likes