Show the selected item in a long list after a submit

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • brian.gaber@pwgsc.gc.ca

    Show the selected item in a long list after a submit

    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.
  • Lasse Reichstein Nielsen

    #2
    Re: Show the selected item in a long list after a submit

    brian.gaber@pwg sc.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 - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: Show the selected item in a long list after a submit

      brian.gaber@pwg sc.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="scrollS elect()">
      ...
      </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, <f806at$ail$1$8 300dec7@news.de mon.co.uk>

      Comment

      • brian.gaber@pwgsc.gc.ca

        #4
        Re: Show the selected item in a long list after a submit

        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.

        Comment

        Working...