Index of selection is wrong after setting a new index within Mozilla

Discussion in 'Javascript' started by Stefan Mueller, Nov 27, 2005.

  1. I choose 'Entry 4' and click then on the button 'Set' to set the index to
    'Entry 2'. If you press now the cursor down key 'Entry 5' instead of 'Entry
    3' shows up with Mozilla Firefox. With Internet Explorer and Opera it works
    fine; 'Entry 3' shows up.

    Is this a bug within Mozilla Firefox or do I have any possibility to change
    this wrong behavior?
    Stefan

    ========================

    <html>
    <body>
    <form name = "MyForm" action = "" method = "post">
    <select name = "MySelection" size = "1">
    <option value = "1">Entry 1
    <option value = "2">Entry 2
    <option value = "3">Entry 3
    <option value = "4">Entry 4
    <option value = "5">Entry 5
    <option value = "6">Entry 6
    </select>

    <input type = "button" value = "Set" onClick =
    "document.MyForm.MySelection.selectedIndex = 1;
    document.MyForm.MySelection.focus();">
    </form>
    </body>
    </html>
    Stefan Mueller, Nov 27, 2005
    #1
    1. Advertising

  2. Stefan,

    I'm afraid I can't offer any solution, but can say that the problem
    happens in my Firefox installation as well (1.0.7). I'd see if it's
    fixed in the latest version of Firefox and if not submit a bug report
    (if hasn't already been submitted).

    If you wanted to work-around it, all I can think of is to keep your own
    selected state in a variable, capture the key events and over-ride
    Firefox's handling of the event - although that seems like more trouble
    than its worth.

    Cheers,
    Matt
    --
    EditMe - Edit your web.
    http://www.editme.com
    Matt - EditMe.com, Nov 28, 2005
    #2
    1. Advertising

  3. Stefan Mueller

    RobG Guest

    Re: Index of selection is wrong after setting a new index withinMozilla

    Stefan Mueller wrote:
    > I choose 'Entry 4' and click then on the button 'Set' to set the index to
    > 'Entry 2'. If you press now the cursor down key 'Entry 5' instead of 'Entry
    > 3' shows up with Mozilla Firefox. With Internet Explorer and Opera it works
    > fine; 'Entry 3' shows up.
    >
    > Is this a bug within Mozilla Firefox or do I have any possibility to change
    > this wrong behavior?


    No, it's not a bug.

    The selectedIndex property of a select element is a number, not a
    method, though some browsers may allow you to use it as such. To change
    the selected option to index 1, use:

    document.MyForm.MySelection[1].selected = true;


    <URL: http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html >
    and
    <URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-85676760 >

    [...]



    --
    Rob
    RobG, Nov 28, 2005
    #3
  4. RobG wrote:

    > Stefan Mueller wrote:
    >> I choose 'Entry 4' and click then on the button 'Set' to set the index to
    >> 'Entry 2'. If you press now the cursor down key 'Entry 5' instead of
    >> 'Entry 3' shows up with Mozilla Firefox. With Internet Explorer and Opera
    >> it works fine; 'Entry 3' shows up.
    >>
    >> Is this a bug within Mozilla Firefox or do I have any possibility to
    >> change this wrong behavior?

    >
    > No, it's not a bug.


    I think it is.

    > The selectedIndex property of a select element is a number, not a
    > method, though some browsers may allow you to use it as such.


    Pardon? He assigned the index number 1 to that property. However, he
    decribes that if the next option is selected manually via the keyboard,
    it is as if 'Entry 4' (index number 3) was still selected. That _is_
    a bug. It can best be observed when using Alt+Cursor Down first to
    expand the list: the selection "jumps" down over two other options.

    Same with other previously selected options and Cursor Up key here
    in Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050922
    Firefox/1.0.7 (Debian package 1.0.7-1) Mnenhy/0.7.2.0

    > To change
    > the selected option to index 1, use:
    >
    > document.MyForm.MySelection[1].selected = true;


    That works only because it is not a multiple select. selectedIndex is
    indeed the read/write property of choice for such elements. You should
    read the references you are using :)


    PointedEars
    Thomas 'PointedEars' Lahn, Nov 28, 2005
    #4
  5. > To change the selected option to index 1, use:
    >
    > document.MyForm.MySelection[1].selected = true;


    Also with you suggestion my Mozilla Firefox experiences the same bug.
    Stefan
    Stefan Mueller, Nov 28, 2005
    #5
  6. Stefan Mueller

    RobG Guest

    Re: Index of selection is wrong after setting a new index withinMozilla

    Thomas 'PointedEars' Lahn wrote:
    > RobG wrote:
    >
    >
    >>Stefan Mueller wrote:
    >>
    >>>I choose 'Entry 4' and click then on the button 'Set' to set the index to
    >>>'Entry 2'. If you press now the cursor down key 'Entry 5' instead of
    >>>'Entry 3' shows up with Mozilla Firefox. With Internet Explorer and Opera
    >>>it works fine; 'Entry 3' shows up.
    >>>
    >>>Is this a bug within Mozilla Firefox or do I have any possibility to
    >>>change this wrong behavior?

    >>
    >>No, it's not a bug.

    >
    > I think it is.
    >
    >>The selectedIndex property of a select element is a number, not a
    >>method, though some browsers may allow you to use it as such.

    >
    > Pardon? He assigned the index number 1 to that property. However, he
    > decribes that if the next option is selected manually via the keyboard,
    > it is as if 'Entry 4' (index number 3) was still selected. That _is_
    > a bug. It can best be observed when using Alt+Cursor Down first to
    > expand the list: the selection "jumps" down over two other options.



    I went over the whole thing again and I was completely off track, I
    missed the point completely. You are exactly right, the arrow keys
    don't select the next option, they go to the next option of whatever was
    previously selected. You can change the selectedIndex programmatically
    all you like, the previous UI-selected option is used for the next
    keyboard-initiated selection.

    And my 'fix' doesn't change that - yes, I'd call it a bug.


    [...]

    > indeed the read/write property of choice for such elements. You should
    > read the references you are using :)


    That is a good point - what are the references?

    Let me go off-topic here a bit. The DOM 2 spec just says it's a number
    and only mentions returned values - should I infer that any property
    that isn't read only can be set? Where does it tell me what will happen
    if I set the value to something?

    The Mozilla Gecko DOM reference doesn't mention it - the form interface
    stuff just talks about the form element.

    The Netscape DevEdge stuff from 2000 on the Mozilla site which says what
    you describe - the selectedIndex property should be used to set the
    selected index property for single selects and for multiple selects
    where previous selections should be cleared at the same time.
    Apparently it was introduced in JavaScript 1.0.

    <URL:
    http://devedge-temp.mozilla.org/library/manuals/2000/javascript/1.3/reference/select.html#1193420
    >


    The Microsoft documentation also mentions that it can be set.

    --
    Rob
    RobG, Nov 28, 2005
    #6
  7. Stefan Mueller

    vdP Guest

    Re: Index of selection is wrong after setting a new index withinMozilla

    Matt - EditMe.com wrote:
    > Stefan,
    >
    > I'm afraid I can't offer any solution, but can say that the problem
    > happens in my Firefox installation as well (1.0.7). I'd see if it's
    > fixed in the latest version of Firefox and if not submit a bug report
    > (if hasn't already been submitted).


    It works fine in my FireFox 1.5.

    vdP
    vdP, Nov 28, 2005
    #7
  8. RobG wrote:

    > Thomas 'PointedEars' Lahn wrote:
    >> [selectedIndex is] indeed the read/write property of choice for
    >> such elements. You should read the references you are using :)

    >
    > That is a good point - what are the references?


    I meant the section of DOM Level 2 HTML you referred us to :)

    > Let me go off-topic here a bit. The DOM 2 spec just says it's a number
    > and only mentions returned values - should I infer that any property
    > that isn't read only can be set?


    Yes.

    > Where does it tell me what will happen if I set the value to something?


    It does not always. It does not in this case.

    > The Mozilla Gecko DOM reference doesn't mention it - the form interface
    > stuff just talks about the form element.


    The Gecko DOM Reference is not quite complete. You can refer to
    XULPlanet for all missing documentation:

    <URL:http://xulplanet.com/references/objref/HTMLSelectElement.html>

    <URL:http://mozref.com/> also once provided information about element
    host objects, however no longer.

    > The Netscape DevEdge stuff from 2000 on the Mozilla site which says what
    > you describe - the selectedIndex property should be used to set the
    > selected index property for single selects and for multiple selects
    > where previous selections should be cleared at the same time.
    > Apparently it was introduced in JavaScript 1.0. [...]


    Exactly. Before JavaScript 1.4, host objects were language features.


    PointedEars
    Thomas 'PointedEars' Lahn, Nov 28, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Florian Feldhaus
    Replies:
    2
    Views:
    609
    Florian Feldhaus
    Sep 3, 2004
  2. Replies:
    0
    Views:
    469
  3. Replies:
    2
    Views:
    1,092
  4. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    271
    Tomasz Chmielewski
    Mar 4, 2008
  5. Replies:
    1
    Views:
    202
Loading...

Share This Page