I am making an autocomplete drop-down list for my Pokemon website, and while the autocompleting drop-down bit works, it's not displaying the HTML entities properly. When I set the input's value to the entity, it simply prints out the text (e.g. ↑
and not a literal up arrow). I'm not sure what I am doing wrong, but here is a simplified version of it:
// There are usually a lot more, but just for simplification only one is shown
const natures = [
{name: "Lonely (Atk ↑ Def↓)"}
]
const natureInput = document.querySelector(".natureInput");
const suggestionsPanelNature = document.querySelector(".natureSuggestions");
// This is just used to see whether they have chosen one of the options
let set_nature = 0;
natureInput.addEventListener('keyup', function() {
set_nature = 0;
const input = natureInput.value;
suggestionsPanelNature.innerHTML = '';
// Find all of the natures that start with the input
const suggestions = natures.filter(function(nature) {
return nature.name.toLowerCase().startsWith(input.toLowerCase());
});
suggestions.forEach(function(suggested) {
// Display all matching natures
const div = document.createElement("div");
div.onclick = function() {
set_nature = 1;
natureInput.value = suggested.name; // This is the line that seems to be causing issues
suggestionsPanelNature.innerHTML = '';
};
div.classList.add("suggestion");
div.innerHTML = suggested.name; // This line, however, works fine
suggestionsPanelNature.appendChild(div);
});
if (input === '') {
suggestionsPanelNature.innerHTML = '';
}
})
So if someone clicked the Lonely (Atk↑ Def↓) option, it would come up in the input box as Lonely (Atk↑ Def↓
), which is not what I want.
If you need anymore information please ask, but otherwise thanks in advance.