I have a select box (Specie) and a typeAhead input field(Breed), Which i need to update on the change of selectbox, I have the following code.
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 profile-fields-margin-bottom">
<select class="form-control select_field_style specie-breed" id="species" name="species" required>
<option disabled selected>Select a Species</option>
<option value="Dog">Dog</option>
<option value="Cat">Cat</option>
<option value="Horse">Horse</option>
</select>
</div>
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 profile-fields-margin-bottom">
<input id="breed" type="text" class="form-control charsonly" name="breed" placeholder="Breed">
</div>
$(document).on('change', '.specie-breed', function() {
let specie = this.value;
$('#breed').typeahead({
source: function (query, process) {
return $.get('/get/breeds/' + specie, { query: query }, function (data) {
console.log(data);
return process(data);
});
}
});
});
Its working but for the first time, The second time change doesn't change the values of the typeahead,
What am i missing here ?
process()
function re-creating the.specie-breed
element? – Acinaciformonchange
event fired. That's going to slow the browser down tremendously after awhile. – Menkenprocess()
function re-creating the .specie-breed element. – Hypochondrium$(document.body).on('change', '.specie-breed', function(e) {
. – Hypochondrium$(document).on(...
also, check the console for errors – Acinaciform