HTML
Код: Выделить всё
Код: Выделить всё
document.addEventListener('DOMContentLoaded', function() {
const searchQueryInput = document.getElementById('search_profile_query');
const myDropdown = document.getElementById('id_my_dropdown');
const container = document.getElementById('dropdown-container');
if(searchQueryInput && myDropdown && container){
searchQueryInput.addEventListener('keyup', function() {
const searchTerm = this.value;
fetch(`/get-dropdown-choices/?q=${searchTerm}`).then(response =>
response.json()).then(data => {
myDropdown.innerHTML = '';
data.choices.forEach(choice => {
const option = document.createElement('option');
option.value = choice[0];
option.textContent = choice[1];
myDropdown.appendChild(option);
});
})
.catch(error => console.error('Error:', error));
});
}
});
Подробнее здесь: https://stackoverflow.com/questions/798 ... javascript
Мобильная версия