Show the selected item in a long list after a submit

B

brian.gaber

I have a Select list with a size of 10, but with more than 10 options
in the list. After I select an item and submit the form I would like
the list be scrolled down to show the previously selected item still
selected and displayed at the top of the Select box.

Thanks.
 
L

Lasse Reichstein Nielsen

I have a Select list with a size of 10, but with more than 10 options
in the list. After I select an item and submit the form I would like
the list be scrolled down to show the previously selected item still
selected and displayed at the top of the Select box.

If you submit the form, a new page is loaded.
If the new page contains the same form, you should make the server
set the selected element on the select control before sending it.

/L
 
T

Thomas 'PointedEars' Lahn

I have a Select list with a size of 10, but with more than 10 options
in the list. After I select an item and submit the form I would like
the list be scrolled down to show the previously selected item still
selected

You can try

<head>
...
<script type="text/javascript">
function scrollSelect()
{
var s = document.forms[...].elements[...];
s.selectedIndex = s.selectedIndex;
}
</script>
</head>

<body onload="scrollSelect()">
...
</body>

but there is no guarantee that it will work as supposed.
and displayed at the top of the Select box.

If you think about this further, you will recognize it cannot be done for
every item.


PointedEars
 
B

brian.gaber

If you submit the form, a new page is loaded.
If the new page contains the same form, you should make the server
set the selected element on the select control before sending it.

Yes, that is what I do now, but if the selected item is not in the
first 10 it will not be shown. I have to scroll down and when I get
to it I will see it selected. I want the scroll to happen
automatically so that the selected item is seen in the size 10 Select.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top