I am developing a unique custom dropdown feature for selecting countries. Here are the specific requirements:
Requirement 1: The dropdown should populate with countries whose names start with the letter typed in the search box.
Requirement 2: Clicking on a country name in the dropdown should mark it as active.
Requirement 3: Display the flag of the selected country on the right side of the search box.
I have successfully implemented the auto-population feature and need assistance with the remaining functionalities.
function autocomplete(inp, arr) {
/*the autocomplete function takes two arguments,
...
});
/*An array containing all the country names in the world:*/
var countries = ["Afghanistan","Albania","Algeria", ... "Zambia","Zimbabwe"];
/*Initialize the autocomplete function on the "myInput" element with the countries array as possible values:*/
autocomplete(document.getElementById("myInput"), countries);
...