When you call your function searchHandler() . Before calling just check a if() condition . create a global variable example = searchterm. if(searchterm) { then only call the function searchHandler() } OR if you want to do it inside searchHandler() function then just put all your code inside if condition. if(keyword) { then rest of the logic }. I hope you understand. Put a upvote if you solve it.