Skip to content

Server Side data return not working #7

@Fzoltan87

Description

@Fzoltan87

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions