headware wrote:[color=blue]
> I have a <select> control that contains many entries. It allows the
> user to multi-select a group of them, click a button, and store the
> selected data in a database. Normally they do this starting at the top
> of the list moving down towards the bottom. The problem I was having
> was that the <select> control was scrolling back to the top of the
> page after the postback and the user would lose their place in the
> <select> control forcing them to scroll through it by hand to find the
> items they just selected. Adding the following javascript helped:
>
> function scrollToSelection()
> {
> var myList = document.forms[0].selectCtrl;
> if(myList.selectedIndex >= 0)
> {
> myList.options[myList.selectedIndex].selected = true;
> }
> }
>
> This works pretty well except that the <select> control stops
> scrolling once the first selected item is showing at the bottom of the
> list. This forces the user to scroll by hand in order to get to the
> items after the selected ones, which is inconvinient. Is there a fix
> for this? Can I make the <select> control scroll down so a few items
> after the last selected item are showing at the bottom?[/color]
Modify the inside of your if statement:
{
indexToShow = selectedIndex + 3;
myList.options[myList.indexToShow].selected = true;
}
That will make the third one after be selected though. That may or may
not be the behavior you are after.
If the select is a MULTIPLE, and you are wanting the last one selected,
it would be easier to have the select server-side generated and have the
one you want selected as SELECTED. Simply loop through the SELECT,
find the last one selected (by comparing its value) and then set it as
selected.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -
http://jibbering.com/faq/