Search/input problem


I have an issue with my wiki viewer project. The concept is to start the search by both clicking on the magnifying glass or by just hitting “enter” on the keyboard.
I used an if statement with the || operator but it only works when the icon is clicked, “enter” doesn’t really lead to anything.

Any help on this issue is appreciated as well as any other input on the project, my pen is below.

Thank you

First of all, love the styling! Beautiful!!

For your input problem, have you considered wrapping your two items into a form?
Using a form allows you to attach your eventhandler to the form’s onSubmit attribute, which captures both enter and a click of a submit button.

1 Like

Hey, I think @batjko has the best solution. Your problem is that you add the keypress eventhandler to the button, but the keypress happens in the text field (search input). So you could wrap the json call inside a function (jsonCall) and split the eventhandlers, like this:

$("#searchIcon").on(“click”, jsonCall);
$("#search input").keypress(function(e){
if(e.which === 13){


Thank you! I got it to work, now I just have to figure out how to declare the function in a variable so I don’t have to copy paste the same thing for two events.

Thanks again!