Preserve The Scroll Position After Post/Submit
Moderator: General Moderators
-
waqarchaudry
- Forum Newbie
- Posts: 4
- Joined: Wed Jul 12, 2006 7:20 pm
Preserve The Scroll Position After Post/Submit
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!
-
waqarchaudry
- Forum Newbie
- Posts: 4
- Joined: Wed Jul 12, 2006 7:20 pm
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:
then after you submit the form you'll use scrollTo() to take you to the same Y position.
ex:
Code: Select all
<form onSubmit="this.scrollPosition.value=document.body.scrollTop">
<input type="hidden" name="scrollPosition">
</form>Code: Select all
<body onLoad="window.scrollTo(0,<?=$_POST['scrollPosition'];?>)">