Page 1 of 1
Preserve The Scroll Position After Post/Submit
Posted: Wed Jul 12, 2006 7:31 pm
by waqarchaudry
Hi Guys! I have a page with different forms etc. some forms are generated dynamically using the database to update etc. I need to keep the scroll to go to the same place where it was when I pressed the submit / update button. I know I have to use scrollTo(x,y) I have been trying but nothings works... Can anyone post a snippet showing how to capture the coordinates etc from multiple forms using the same javascript. Cheers!
Posted: Wed Jul 12, 2006 7:52 pm
by MarK (CZ)
You could use the NAME attribute of A tag instead.
Posted: Wed Jul 12, 2006 8:52 pm
by waqarchaudry
Please explain I dont understand.... Example will be good thank you!
Posted: Wed Jul 12, 2006 11:56 pm
by Burrito
you could use scrollTo() as you suggested. You'll just need to capture the y position of the page on submit of your form and pass it to the next page.
ex:
Code: Select all
<form onSubmit="this.scrollPosition.value=document.body.scrollTop">
<input type="hidden" name="scrollPosition">
</form>
then after you submit the form you'll use scrollTo() to take you to the same Y position.
Code: Select all
<body onLoad="window.scrollTo(0,<?=$_POST['scrollPosition'];?>)">