Closed Bug 224023 Opened 18 years ago Closed 6 years ago

Listbox (select) does not scroll to selected line


(Core :: Layout: Form Controls, defect)

Not set





(Reporter: matthias_rgaw, Unassigned)


(Keywords: testcase)


(2 files)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007

If a listbox (select) is placed within a table where the cell (<td>) has the
attribute align="center", the listbox does not initially show the selected line.

html code to reproduce behavior:

<head><title>Listbox Problem</title>
<td align="center">
<select id="day" name="day" tabindex="1" size="7">
<option value="20.09.2003">Sa 20.09.2003</option>
<option value="21.09.2003">So 21.09.2003</option>
<option value="22.09.2003">Mo 22.09.2003</option>
<option value="23.09.2003">Di 23.09.2003</option>
<option value="24.09.2003">Mi 24.09.2003</option>
<option value="25.09.2003">Do 25.09.2003</option>
<option value="26.09.2003">Fr 26.09.2003</option>
<option value="27.09.2003">Sa 27.09.2003</option>

<option value="28.09.2003">So 28.09.2003</option>
<option value="29.09.2003">Mo 29.09.2003</option>
<option value="30.09.2003">Di 30.09.2003</option>
<option value="01.10.2003">Mi 01.10.2003</option>
<option value="02.10.2003">Do 02.10.2003</option>
<option value="03.10.2003" selected >Fr 03.10.2003</option>
<option value="04.10.2003">Sa 04.10.2003</option>
<option value="05.10.2003">So 05.10.2003</option>
<option value="06.10.2003">Mo 06.10.2003</option>

Reproducible: Always

Steps to Reproduce:
1. Save above code into a html document
2. open this document

Actual Results:  
listbox shows first line

Expected Results:  
listbox should scroll to the selected line
Why do we ever scroll to the <option selected>?  That seems like odd behavior to
are you serious?
%) matthias
Yes, I am.  Perhaps I should clarify the question... "I just looked through the
listbox code, and I fail to see what would trigger this scrolling.  What code
actually triggers it?"
Adding me to the CC list.

I have just noticed this bug when testing a PHP script. I have found out that IE
behaviour is exactly the requested on this bug: if an item is selected by
default, the select element should be scrolled to allow seeing the item
selected. I suggest to change the status to NEW.

Oh, and it is important to keep in mind that the attribute "align=center" in the
TD tag is not necessary for reproducing the bug.
I have made a little JavaScript function as a workaround for this bug. It's
quite simple and more or less secure:

function ScrollSelect(sel){
  //function used as workaround of Mozilla bug:

  if ((sel.options.length>1)&&(sel.selectedIndex!=-1)){

    i = sel.selectedIndex;

    if (sel.options.length-1!=i) 
      //not the last option selected


This function could be called by the page using something like (supposing
"form1" as the name of the form, and "sel1" the name of the select input control):

<body onLoad="ScrollSelect(window.document.form1.sel1);">

Although this workaround won't be useful when JavaScript is disabled for the
browser. This is the reason for me to think that we need this bug to be resolved
for Mozilla (at least, it should be marked as NEW).

I had a mistake in my comment #4. The align="center" is a requisite for the
reproduction of the bug.

The best way to notice the bug is displaying the HTML example that gave
Matthias. If the attribute align="center" is removed, Mozilla scrolls the SELECT
(BTW, I am answering to Boris, I think).
confirmed with trunk build 20040111908
I can't see why a list should behave differently with and without align="center"
on the cell, it's not consistent.
Ever confirmed: true
I have found a very representative URL in bugzilla for this bug:
(Perhaps it is useful to have this URL on the URL field for the bug, but I have
not enough permissions to change it.)

As you see, when you display that page, the SELECT control which allows
selecting the Component, has a selected value, but the Select is not properly
scrolled (if you scroll the SELECT manually, you can see the selected item).

I also have made an optimization for the workaround in JavaScript that I noticed:

function ScrollSelect(sel){
  //function used as workaround for Mozilla bug:

  if ((sel.options.length>1)&&(sel.selectedIndex>0)){
Attached file Testcase
Bug still occurs, 2004-07-18-05 trunk Linux.  The regression occured somewhere
between Mozilla 1.3 and 1.4 releases.
Severity: minor → normal
Keywords: testcase
OS: Windows XP → All
Using javascript to scroll a listbox by setting selectedIndex to a position
fails when disabled is set to 'true' and then back to 'false'.	This attachment
demonstrates this bug.
Attachment #154028 - Attachment mime type: application/octet-stream → video/mpeg
However this can be made to work by a work-around by replacing the innerHTML of the select statement as follows -
<option value="Page1">
<option value="Page2">
<option value="Page3">
<option value="Page4"> 

If option 3 needs to be as selected then using innerHTML replace the option 3 html text as:
<option value="Page3" selected="selected">

So it now looks like -

<option value="Page1">
<option value="Page2">
<option value="Page3" selected="selected">
<option value="Page4"> 

This way I am able to set the option as selected.
Assignee: layout.form-controls → nobody
QA Contact: ian → layout.form-controls
Works for me, both when loading the test attachment directly from Bugzilla and from
a local saved file.  Nightly 37.0a1 (2015-01-01) on Linux64.
Can anyone else reproduce the problem?
Flags: needinfo?(matthias_rgaw)
Whiteboard: [closeme 2015-01-26]
Resolved per whiteboard and Comment 13
Closed: 6 years ago
Flags: needinfo?(matthias_rgaw)
Resolution: --- → WORKSFORME
Whiteboard: [closeme 2015-01-26]
You need to log in before you can comment on or make changes to this bug.