I use alert boxes to warn the user about errors when submitting a form on a website I am working on, but each time I click the “ok” button to close the alert box, the page go back to the top and I need to scroll down again to see the form.
I checked other website but this does not happen despite the code is pretty much the same.
What is wrong?
The page jumping to the top is usually a sign that you are linking to
'#'but not cancelling the action – I’ve never seen that happen on a form submit myself.Here’s an example of something which might cause the page to jump:
After the page jumps, look in the address bar. Is there a # at the end?
Just make sure that
onclickoronsubmitfunctions always return false if you don’t want the default action to occur.