Why does my page freeze on this?
<script>
var targetInput = document.getElementById(“aircraft”),
results = document.getElementById(“autocomplete-results”),
aircraftList = [‘aa’,’bb’,’cc’,’dd’,’ee’],
matches = [];
targetInput.focus();
targetInput.addEventListener(“keyup”, function(event){
results.innterHTML = ”;
toggleResults(“hide”);
if (this.value.length > 0){
matches = getMatches(this.value);
if (matches.length > 0){
displayMatches(matches);
}
}
});
function toggleResults(action){
if (action == ‘show’){
results.classList.add(‘visible’);
} else {
results.classList.remove(‘visible’);
}
}
function getMatches (inputText){
var matchList = [];
for(var i = 0; i < aircraftList.length; i++){
if (aircraftList[i].toLowerCase().indexOf(inputText.toLowerCase()) != -1){
matchList.push(aircraftList[i]);
}
}
return matchList;
}
function displayMatches(matchList){
var j = 0;
while (j < matchList.length){
results.innerHTML += ‘<li class=”result”>’ + matchList[j] + ‘</li>’;
}
toggleResults(“show”);
}
</script>