How to create a search bar that DOESN'T GIVE RESULTS WHEN NOTHING IS WRITTEN ON IT.
My JavaScript code so far: function search() { // Declare variables var input, filter, ul, li, a, i; input = document.getElementById('input'); filter = input.value.toUpperCase(); ul = document.getElementById('ops'); li = ul.getElementsByTagName('li'); // Loop through all list items, and hide those who don't match the search query for (i = 0; i < li.length; i++) { a = li[i].getElementsByTagName("a")[0]; if (a.innerHTML.toUpperCase().indexOf(filter) > 1) { li[i].style.display = "block"; } else{ li[i].style.display = "none"; } if (a.innerHTML.toUpperCase().indexOf(filter) <= -1) { li[i].style.display = "none"; } } }