Solved

Div auto scroll to bottom

Posted on 2010-09-11
13
709 Views
Last Modified: 2012-05-10
Ive been trying to get a Div to load, and scroll to the bottom. The idea is to have a list of transactions, and have the div scroll to the bottom.

I found an article at 'http://radio.javaranch.com/pascarello/2005/12/14/1134573598403.html', and tried to put it in the onload of the div, but it doesnt scroll to the bottom. It doesnt produce any errors, just doenst work :-(

Any idea what Im doing wrong?

Thanks in advance!!!


<div id="divTransList" style="width:100%; height:150px; overflow:auto;" onload="javascript: var objDiv = document.getElementById('divTransList'); objDiv.scrollTop = objDiv.scrollHeight;">
        hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>hello</br>
    </div>

Open in new window

0
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 2

Expert Comment

by:kostantinos1995
ID: 33652966
The given page cannot be found!
0
 

Author Comment

by:tonelm54
ID: 33652970
Sorry, its including the ' at the end of the hyperlink.

The url is:-
http://radio.javaranch.com/pascarello/2005/12/14/1134573598403.html
0
 
LVL 2

Expert Comment

by:kostantinos1995
ID: 33652994
One, you have a syntax error "" should be typed "" and two anchor points use the name attribute, check out the following code:
<div id="divTransList" name="divTransList" style="width:100%; height:150px; overflow:auto;">

hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />

</div>

<script type="text/javascript">
window.onload= function event(onload) {window.location = "#divTransList"};
</script>

Open in new window

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 4

Expert Comment

by:antonybrahin
ID: 33652996
put the script in a function and call it after the div loads.
0
 
LVL 2

Expert Comment

by:kostantinos1995
ID: 33652998
Sorry:  ->
0
 
LVL 2

Expert Comment

by:kostantinos1995
ID: 33653004
It takes br and interpretes it as real code, the point is you have mistyped it.
0
 
LVL 2

Expert Comment

by:kostantinos1995
ID: 33653011
Like this:



hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello



<script type="text/javascript">
function jumpToAnchor (anchorPoint) {
      window.location = "#" + anchorPoint;
}

jumpToAnchor("divTransList");
</script>
0
 
LVL 2

Expert Comment

by:kostantinos1995
ID: 33653013
Like this:
<div id="divTransList" name="divTransList" style="width:100%; height:150px; overflow:auto;">

hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />

</div>

<script type="text/javascript">
function jumpToAnchor (anchorPoint) {
	window.location = "#" + anchorPoint;
}

jumpToAnchor("divTransList");
</script>

Open in new window

0
 
LVL 2

Expert Comment

by:kostantinos1995
ID: 33653023
I just saw the page let me change the code a little bit.
0
 
LVL 2

Accepted Solution

by:
kostantinos1995 earned 500 total points
ID: 33653045
I'm sure this is what you want:
<div id="divTransList" name="divTransList" style="width:100%; height:150px; overflow:auto;">

</div>

<script type="text/javascript">
function addTimeToDIV () {
	objDiv= document.getElementById('divTransList');
	// Your code goes here
	objDiv.innerHTML += new Date().getTime() + "<br />";
	// and ends here
	objDiv.scrollTop= objDiv.scrollHeight;
}

setInterval ("addTimeToDIV()", 500 );
</script>

Open in new window

0
 
LVL 14

Expert Comment

by:sam2912
ID: 33653540
if you only want the div to jump to the bottom once, on page load, do this:
<script type="text/javascript">
window.onload = function() {
   var elem = document.getElementById('divTransList');
   elem.scrollTop = elem.scrollHeight;
}
</script>

Open in new window

0
 
LVL 2

Expert Comment

by:sqlgang
ID: 33656433
Code for IE:

<html>
<body>
    <script language="javascript" type="text/javascript">
        function MoveDivToBottom() {
            var obj = document.getElementById("divTransList");
            document.getElementById("foodiv").innerHTML = document.getElementById("foodiv").innerHTML + "::" + obj.scrollHeight + ">>" + obj.offsetHeight;
            obj.scrollTop = obj.scrollHeight;
        }
    </script>
<div id="foodiv" style="display:none"></div>    
    <div id="divTransList" style="width: 100%; height: 150px; overflow: auto;">hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />
        hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello
        <br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />hello<br />
        hello<br />hello<br />hello        End
</div><script language="javascript" type="text/javascript">MoveDivToBottom();</script>

</body>
</html>

Open in new window

0
 
LVL 2

Expert Comment

by:sqlgang
ID: 33656438
For Non IE: You may remove the foo div and its innerHTML manipulation from the MovDivToBotom - as it is specific for the IE only where it needs some time to move to bottom - which it gets by doing some funny stuff.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Add somewhat of a wildcard to your javascript 12 30
How do I post more than 1 item to php backend 24 31
Can anyone help me find this preloader? 51 43
Slush on text 2 11
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question