While I agree with Portable’s advice, I’m looking at your code.
Do I understand that you have newSearch declared outside this event handler (to make it global also? If you’ve already declared newSearch outside of the event handler and then redeclare it (as you seem to do on the first like of your event handler) then you now have two instances with the same name and you get into some complicated scoping issues. Inside the event handler, the local variable would be accessed as newSearch but to access the global one, it would have to be something like window.newSearch to make it clear. But if a global variable is already declared, then don’t redeclare it.
If you really, really wanted to do it, then I’d remove the newSearch declaration in the event handler (assuming that my inference is correct, that it’s declared somewhere else globally).
But Portable is right - you have to be careful with global variables, especially when dealing with asynchronous functions You should probably rethink how your doing your algorithm and try to put it in the event handler, even if you have to call other functions from the event handler.