Set select options dynamically in catalog product page in Magento Admin panel

旧时模样 提交于 2019-12-05 12:17:27

try the below code if you have data inside select box in object or array in JS then you can filter it out easily and append it to select box Here's Demo DEMO

var data = {
  "A": ["Air", "Apple", "Ant"],
  "B": ["Water", "Mango", "Fly"]
}

jQuery('#parent').on('change', function() {
  var tempData = data[this.value];
  var selectChild = jQuery('#child');
  jQuery('option', selectChild).remove();
  for (var i = 0; i < tempData.length; i++) {
    var option = new Option(tempData[i], tempData[i]);
    selectChild.append(jQuery(option));
  }

});
<select id="parent">
  <option value="">Select Parent</option>
  <option value="A">A</option>
  <option value="B">B</option>
</select>
<select id="child">
  <option value="">Select Child</option>
</select>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!