By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

Show the selected item in a long list after a submit

P: n/a
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.
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
br*********@pwgsc.gc.ca writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jun 27 '08 #2

P: n/a
br*********@pwgsc.gc.ca wrote:
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
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Jun 27 '08 #3

P: n/a
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.
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.