-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
The data coming from the server side is not loaded into the dropdown list when we add dselect (If I don't use the dselect add-on, the data reload works).
The code HTML:
<label for="states" class="control-label">Country</label>
<select name="dc_countryID" id="country" class="form-select rounded-0 selectlist">
<option value="0">Select</option>
<option value="0">USA</option>
<option value="0">Brazil</option>
</select>
<label for="states" class="control-label">State</label>
<select name="dc_stateID" id="states" class="form-select rounded-0 selectlist">
<option value="0">Select</option>
</select>
<label for="cities" class="control-label">City</label>
<select name="dc_cityID" id="cities" class="form-select rounded-0 selectlist">
<option value="0">Select</option>
</select>
Javascript code: (#states and #cities select tag ID)
let selectList = document.querySelectorAll('.selectlist');
if (selectList != null) {
for (const sl of selectList) {
dselect(sl, { search: true });
}
}
$(document).ready(function(){
$("#country").on("change",function() {
var countryID = $(this).val();
$.ajax({
url: "action_ajax.php",
type: "POST",
cache: false,
data: {countryID:countryID},
success: function(data) {
console.log(data);
$("#states").html(data);
},
error: function (jqXHR, textStatus, errorThrown) {
errorFunction();
}
});
});
$("#states").on("change",function() {
var statesID = $(this).val();
$.ajax({
url: "action_ajax.php",
type: "POST",
cache: false,
data: {statesID:statesID},
success: function(data) {
console.log(data);
$("#cities").html(data);
},
error: function (jqXHR, textStatus, errorThrown) {
errorFunction();
}
});
});
});
Metadata
Metadata
Assignees
Labels
No labels