I am submitting a form via an anchor tag and javascript.
<a onclick="submit_form();">Submit</a>
As soon as the button is clicked, the page immediately scrolls to the top of the page and continues the normal form submission process.
How can I keep the page from scrolling to the top and why does it do that?
Change your OnClick event to be in the HREF.
<a href="JavaScript:submit_form();">Submit</a>
Or return False so that it doesn't continue processing the click
<a onClick="submit_form(); return false;">Submit</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With