tags:

views:

77

answers:

3

How to scroll to top of the page in php with javascript

scroll(0,0); -> this is not working? On click of submit, i call a function to validate the form and incase of error i will be setting the errormessage thru innerhtml and need to scroll to top of the page without submitting.

Everything works...but its not scrolling to top of the page

A: 

How about trying window.scrollTo(0,0). It is basically the same thing as scroll(0,0).

If it does not work, show us more code.

epascarello
+1  A: 

Use window property scrollTop (MSDN, MDC) to set number of pixels to scroll offset.

window.scrollTop = '0';
nemisj
A: 

Scrolling to the absolute top of the page can be achieved by either

window.scrollTo(0,0);

or

window.location = "#";

Note that the second method will append "#" to the current URL.

Justin Johnson