Skip to content
Advertisement

Page refreshes after I hit the button

It’s a simple counting vowels page. When I insert a word WITH vowels, the result shows up for a second and then page refreshes. When there are no vowels, the output is not as expected and then the page refreshes again. Could anyone help me out please?

JavaScript
JavaScript

Advertisement

Answer

You are submitting the form when using default buttons.

The event you wanted is not passed as you expect – it is the button that is passed.

EITHER use type=button OR better: use event.preventDefault as now, but on the submit event

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