Firstly, I am no Javascript expert. I'd like to add a feature to a SELECT box I am using which automatically scrolls to the end when a new item is added, but only if the user has not scrolled up.
Basically, when a user is reviewing older entries, I don't want new arrivals to snap the position to the end of the select list. However, if the user scrolls down to the bottom using the scroll bar, new arrivals shoudl automatically be brought into view.
Here is what I have so far
<script type="text/javascript">
function AddItem(s)
{
document.getElementById('content').add(new Option(s));
// Scroll to end - cant remember why I am using this pair of commands :)
document.getElementById('content').selectedIndex = document.getElementById('content').length - 1;
document.getElementById('content').selectedIndex = document.getElementById('content').length + 1;
}
</script>
I am expecting to have to perform a test to see if the last but one item is visible. If so, we are at the bottom and should perform the autoscroll. Is this correct?
Thanks JS Masters
Simon