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

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

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


P: n/a
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

Nov 28 '05 #2

P: n/a
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-HTM...t-binding.html >
and
<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-85676760 >

[...]

--
Rob
Nov 28 '05 #3

P: n/a
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
Nov 28 '05 #4

P: n/a
> 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
Nov 28 '05 #5

P: n/a
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/libr...t.html#1193420


The Microsoft documentation also mentions that it can be set.

--
Rob
Nov 28 '05 #6

P: n/a
vdP
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
Nov 28 '05 #7

P: n/a
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
Nov 28 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.