I'm encountering a very strange issue with an onkeyup function. Depending how fast the person types, the function that is triggered by typing may run multiple times.
var inputFilter = document.getElementById('inputFilter');
inputFilter.onkeyup = function(e, value) {
e.preventDefault();
value = e.target.value
if (value.length >= 3) {
console.log(value);
getItems(value);
}
};
If I type slowly, the getItems() function runs perfectly, but if I type really fast it behaves strangely. The getItems() function pulls data from a SharePoint list using Ajax(XMLHttpRequest()), and creates a table with the results. If I type slowly, the table is just fine, but if I type fast, each table row duplicates. I added to the getItems() function a body.innerHTML = '' to make sure it empties the table's body with each run of of the function:
const table = document.getElementById('smeTable'),
body = table.getElementsByTagName('tbody')[0];
body.innerHTML = '';
I'm not a programmer, and probably will get many down votes for this probably silly question, but I'm puzzled by this issue. Any ideas would be appreciated. Thank you.