• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

Scrolling a Select Box

I have a select box that is dynamically filled with items via database.  One item will be returned with the "selected"
parameter on.  Is it possible to scroll the box so that the selected item will be shown, and if so, can I see some example code?
1 Solution

A select box scrolls automatically in order to show the selected value :

VBScript :

MarcheSelect = Request("CodeMarche")
<BR><SELECT NAME = "CodeMarche" SIZE="1" onChange="this.form.submit()">

<OPTION VALUE = ""> Any End-use  </OPTION>      <%

Do While Not Rs1.EOF
   If Cstr(Rs1("CodeMarche")) = MarcheSelect Then            %><OPTION VALUE = "<% = Rs1("CodeMarche") %>"            SELECTED > <% =Rs1("Libelle")%> <%
      %><OPTION VALUE = "<% = Rs1("CodeMarche") %>"  > <% =Rs1("Libelle")%> <%

   End If

<% Rs1.MoveNext
Loop %>

JavaScript :
The following  function might meet others sides of the problem :

1°) It stores in two hidden inputs (named "CodeMarche" and "CodeFonction") of the 3rd frame,  the selected values of two select boxes (named "CodeMarche" and "CodeFonction" as well), which are located respectively in the 1st and the 2nd frame, in the 1st form :

-> " = parent.frames[0].document.forms[0].CodeMarche. ..."
-> " = parent.frames[1].document.forms[0].CodeFonction. ..."

2°) The selected value of "CodeMarche" is 'unique' , but the selected value of "CodeFonction" is 'multiple' (hence, the 'for' is compulsory, because Netscape is quite fussy with the multiple attribute,
and if the result is to be "value1, value2, ...", you have to handle the comma, contrary to checkboxes).

function RecupParam(form){

form.CodeMarche.value = parent.frames[0].document.forms[0].CodeMarche.options[parent.frames[0].document.forms[0].CodeMarche.selectedIndex].value;

form.CodeFonction.value = "";
for (var i = 0; i < parent.frames[1].document.forms[0].CodeFonction.options.length; i++) {
   if (parent.frames[1].document.forms[0].CodeFonction.options[i].selected){
      if (form.CodeFonction.value != "" && form.CodeFonction.value != null){
            form.CodeFonction.value += ", "
      form.CodeFonction.value += parent.frames[1].document.forms[0].CodeFonction.options[i].value;

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now