Skip to content
Advertisement

Uncaught ReferenceError: showResults is not defined at HTMLInputElement.onkeyup

When I keypress in the input console is continuously showing the error:

Uncaught ReferenceError: showResults is not defined at HTMLInputElement.onkeyup

As you can see in the code, the function is defined. When I remove the AJAX code it starts working. I am unable to find out what the problem is.

JavaScript
JavaScript
JavaScript

Advertisement

Answer

When you have issues in JS, always open devtools and check the console for errors. The problem in this case is because you have a ; in the wring place – after url: "/search";. This means the function is not defined correctly and cannot be called. Change the ; to a , and the code works.

As an aside to the problem, don’t use the onX event attributes in your HTML. They are massively outdated and no longer good practice. Bind unobtrusive event handlers using jQuery’s on() method or the plain JS addEventListener()

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement