Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Index of selection is wrong after setting a new index within Mozilla

Reply
Thread Tools

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

 
 
Stefan Mueller
Guest
Posts: n/a
 
      11-27-2005
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>


 
Reply With Quote
 
 
 
 
Matt - EditMe.com
Guest
Posts: n/a
 
      11-28-2005
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

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      11-28-2005
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
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      11-28-2005
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
 
Reply With Quote
 
Stefan Mueller
Guest
Posts: n/a
 
      11-28-2005
> 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


 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      11-28-2005
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
 
Reply With Quote
 
vdP
Guest
Posts: n/a
 
      11-28-2005
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
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      11-28-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting index-15, index-9, index-110 "the human way"? Tomasz Chmielewski Perl Misc 4 03-04-2008 05:01 PM
selection structure nested within another selection structure 4Ankit@gmail.com Javascript 1 12-07-2006 11:47 AM
setting Onclick and setting the ClientID in behind code isn't working in Mozilla davidr@sharpesoft.com ASP .Net 2 08-22-2006 09:30 PM
setting Onclick and setting the ClientID in behind code isn't working in Mozilla davidr@sharpesoft.com ASP .Net 0 08-21-2006 11:55 PM
Wrong height of an image within a div in Mozilla Firebird Florian Feldhaus HTML 2 09-03-2004 11:46 AM



Advertisments