Below is my code to populate the second select based on the first select and I am using Jquery nice-select.
when I select in first select second select should populate but it doesn't. but when I inspect element it is populated in the select tag but doesn't load in jquery nice-select
can some one help me with solution. I also tried adding :
$("#edct").html(data).nice-select('refresh');
Note I don't want to use Bootstrap-select because my website is not built with bootstrap CSS
$(document).ready(function () {
$('select').niceSelect();
});
var eduBak = {};
eduBak['Maruti Suzuki'] = ['Delhi', 'Mumbai', 'Chennai', 'Kolkata', 'Bangalore', 'Hyderabade', 'Pune'];
eduBak['Hyundai'] = ['Alabama', 'Alaska', 'Arizona'];
eduBak['Tata'] = ['England', 'Northrn Ireland', 'Scotland', 'Wales', 'other'];
eduBak['Mahindra'] = ['Alberta ', 'Brirish Columbia', 'Manitoba', 'others'];
eduBak['Toyota'] = ['Singapore', 'others'];
eduBak['Others'] = ['Others']
$('#edu').on('change', function() {
var edu = document.getElementById("edu");
var model = document.getElementById("edct");
var educ = edu.value;
while (model.options.length) {
model.remove(0);
}
var ed = eduBak[educ];
if (ed) {
var i;
for (i = 0; i < ed.length; i++) {
var e = new Option(ed[i], ed[i]);
model.options.add(e);
}
}
});
.nice-select {
border: solid 1px #CCC;
-webkit-tap-highlight-color: transparent;
clear: both;
border-radius:2px;
cursor: pointer;
display: block;
float: left;
font-family: inherit;
font-weight: normal;
line-height: 36px;
outline: none;
padding: 0 10px !Important;
position: relative;
text-align: left !important;
-webkit-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
white-space: nowrap;
width: auto;
margin-bottom: 18px
}
.nice-select:after {
border-bottom: 2px solid #999;
border-right: 2px solid #999;
content: '';
display: block;
height: 5px;
margin-top: -4px;
pointer-events: none;
position: absolute;
right: 12px;
top: 50%;
-webkit-transform-origin: 66% 66%;
-ms-transform-origin: 66% 66%;
transform-origin: 66% 66%;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transition: all 0.15s ease-in-out;
transition: all 0.15s ease-in-out;
width: 5px; }
.nice-select.open:after {
-webkit-transform: rotate(-135deg);
-ms-transform: rotate(-135deg);
transform: rotate(-135deg); }
.nice-select.open {
border:1px solid #ffc107
}
.nice-select.open .list {
border:1px solid #ffc107;
opacity: 1;
pointer-events: auto;
-webkit-transform: scale(1) translateY(0);
-ms-transform: scale(1) translateY(0);
transform: scale(1) translateY(0); }
.nice-select.disabled:after {
border-color: #cccccc; }
.nice-select.wide {
width: 100%; }
.nice-select.wide .list {
left: 0 !important;
right: 0 !important; }
.nice-select.right {
float: right; }
.nice-select.right .list {
left: auto;
right: 0; }
.nice-select.small {
font-size: 12px;
height: 36px;
line-height: 34px; }
.nice-select.small:after {
height: 4px;
width: 4px; }
.nice-select.small .option {
line-height: 34px;
min-height: 34px; }
.nice-select .list {
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 0 1px rgba(68, 68, 68, 0.11);
box-sizing: border-box;
margin-top: 0;
opacity: 0;
overflow: hidden;
padding: 0;
pointer-events: none;
position: absolute;
top: 100%;
left: 0;
-webkit-transform-origin: 50% 0;
-ms-transform-origin: 50% 0;
transform-origin: 50% 0;
-webkit-transform: scale(0.75) translateY(-21px);
-ms-transform: scale(0.75) translateY(-21px);
transform: scale(0.75) translateY(-21px);
-webkit-transition: all 0.2s cubic-bezier(0.5, 0, 0, 1.25), opacity 0.15s ease-out;
transition: all 0.2s cubic-bezier(0.5, 0, 0, 1.25), opacity 0.15s ease-out;
z-index: 9; }
.nice-select .list:hover .option:not(:hover) {
background-color: transparent !important; }
.nice-select .option {
cursor: pointer;
font-weight: 400;
line-height: 25px;
list-style: none;
min-height: 25px;
outline: none;
padding-left: 18px;
padding-right: 29px;
text-align: left;
-webkit-transition: all 0.2s;
transition: all 0.2s; }
.nice-select .option:hover, .nice-select .option.focus, .nice-select .option.selected.focus {
background-color: #f6f6f6; }
.nice-select .option.selected {
font-weight: bold; }
.nice-select .option.disabled {
background-color: transparent;
color: #999;
cursor: default; }
.no-csspointerevents .nice-select .list {
display: none; }
.no-csspointerevents .nice-select.open .list {
display: block; }
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-nice-select/1.1.0/css/nice-select.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-nice-select/1.1.0/js/jquery.nice-select.js"></script>
<div class="frm-row">
<label>Brand</label>
<select class="wide" id="edu">
<option data-display="Select">Select Brand</option>
<option>Maruti Suzuki</option>
<option>Hyundai</option>
<option>Tata</option>
<option>Mahindra</option>
<option>Toyota</option>
</select>
</div>
<div class="frm-row">
<label>Model</label>
<select class="wide" id="edct">
<option data-display="Select">Select Model</option>
</select>
</div>
