Preserve The Scroll Position After Post/Submit

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
waqarchaudry
Forum Newbie
Posts: 4
Joined: Wed Jul 12, 2006 7:20 pm

Preserve The Scroll Position After Post/Submit

Post 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!
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

You could use the NAME attribute of A tag instead.
waqarchaudry
Forum Newbie
Posts: 4
Joined: Wed Jul 12, 2006 7:20 pm

Post by waqarchaudry »

Please explain I dont understand.... Example will be good thank you!
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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'];?>)">
Post Reply