Wikipedia viewer feedback and litle problem

Hello,
I have almost finished my project. Here is link to it: https://codepen.io/leszczu/pen/YQKpwp
I got one problem though. When I press search button everything works fine, however when I press “enter” I get no results(sometimes I get results only for half a second). I have checked similiar projects and everything should be fine in my opinion. Could someone help me?
regards
Tomasz

Hi,

when you press “enter” inside of a form, you are submitting the form (and the page reloads).
You could try to bind your keypress event to the form (and add event.preventDefault()) or you could simply use the submit function, e.g. .submit(function(event) {event.preventDefault();...}

Also, it looks like the clearPreviousResults function is not working as it should. I’d try to remove "div" from .children

1 Like

took me way too long to figure this out hahahaha but i wanted some practice debugging.

after almost an hour of troubleshooting, i determined that since you wrapped the input tags in form tags, it is reloading the page when you press enter.

at first i tried just deleting the form tags, but it looks like some of your styling is connected to that

another workaround would be to add

event.preventDefault()

to the keypress event to prevent the page from reloading.

edit: looks like christophherr beat me to it

1 Like

Hi,
thank You very much for advice. Sometimes you can get stuck with a simple problem for a very long time.
best regards
Tomasz