DEV Community

[Comment from a deleted post]
Collapse
 
jordanfinners profile image
Jordan Finneran

This is because when you submit a form, the default behaviour for a HTML form is to submit to a URL, which is the page refresh you are seeing. You can read about it more w3schools.com/html/html_forms_attr...

If you want to handle this yourself, you need to preventDefault on the submit event, which halts its default behaviour.
You can then use Javascript to get the form values and submit them via fetch, which means you also don't need any additional dependancies.
Heres my blog on how to get the values of the form dev.to/jordanfinners/how-to-easily...

And this blog will explain how to use fetch
freecodecamp.org/news/fetch-api-ch...