• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using JS to maintain the scroll position of a DIV upon postback

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all:

We are attempting to use JS to maintain the scroll position of a DIV upon postback of a standard FORM. There are several solutions online for ASP, PHP, etc... however we code in a proprietary CGI construct, thus those solutions have not worked for us.

I found this script on your page, written several years ago by Eric Pascarello (see below). It works perfectly for what we are trying to accomplish, less one major issue - it writes to a cookie, and we need it to write to a hidden field.

Through course of full disclosure, I am a software engineer and fairly well versed in various forms of scripting - however, I am embarrassingly TERRIBLE at JS. I am sure the solution is simple, and staring me in the face, but I am not sure what to change.

<script type="text/javascript">
window.onload = function(){
var strCook = document.cookie;
if(strCook.indexOf("!~")!=0){
var intS = strCook.indexOf("!~");
var intE = strCook.indexOf("~!");
var strPos = strCook.substring(intS+2,intE);
document.getElementById("'+divTest4+'").scrollTop = strPos;
}
}
function SetDivPosition(){
var intY = document.getElementById("'+divTest4+'").scrollTop;
document.title = intY;
document.cookie = "yPos=!~" + intY + "~!";
}
</script>
<div id="'+divTest4+'" onscroll="SetDivPosition()" style="width:150px;height:200px;overflow:auto">
1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>
1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>
1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>
1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>
ERIC<br/>
1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>
1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>
1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>
1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>
</div>


Thanks in advance to anyone who can help.

G.C. Hutson
Sadien Intellectual Property
gch@sadien.com
(615) 869-0022 x 8100
 
Gc Hutson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Explanation: The '+divTest4+' is our variable call. Simply change that to divTest to make it work in standard HTML.

Thanks again.

GC Hutson
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic