not possible to access SELECT element's "options" array from a DOMElement.

VERIFIED WORKSFORME

Status

()

Core
Layout: Form Controls
P3
normal
VERIFIED WORKSFORME
19 years ago
18 years ago

People

(Reporter: Ben Goodger (use ben at mozilla dot org for email), Assigned: Eric Pollmann)

Tracking

Trunk
x86
Windows 95
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

What happens:

I have a select element with an ID attribute:
<SELECT ID="foo">
 <OPTION VALUE="value1">Option 1</OPTION>
 <OPTION VALUE="value2">Option 2</OPTION>
</SELECT>

I can only get this element easily via

selectElement = document.getElementById("foo");

However when I do this I cannot get the "options" array property of the select
element as I would normally do:

index = selectElement.options.selectedIndex;
value = selectElement.options[index].value;

returns an error "selectElement.options has no properties"

However if I create a form and give the element a name, I can:

selectElement = document.form1.select1;
.. as above ..

Since in both cases selectElement refers to the same object, I would have
thought that I would be able to access identical properties.
*** Bug 20029 has been marked as a duplicate of this bug. ***

Updated

19 years ago
Assignee: karnaze → pollmann

Comment 2

19 years ago
Reassigning to Eric.

Comment 3

19 years ago
QA Contact update.
(Assignee)

Updated

19 years ago
Status: NEW → ASSIGNED
Target Milestone: M14
(Assignee)

Comment 4

19 years ago
Don't know why this might be.  I'm taking a look at this.  But until then please
also note:

According to the spec, "selectedIndex" is a property of the select element, and
not a property of the options array.  Your example should read:

selectElement = document.getElementById("foo");
index = selectElement.selectedIndex;
value = selectElement.options[index].value;

This is, however, a backwards compatability issue and is being addressed.  See
bug 12513
(Assignee)

Comment 5

19 years ago
Created attachment 3215 [details]
test case
(Assignee)

Updated

19 years ago
Status: ASSIGNED → RESOLVED
Last Resolved: 19 years ago
Resolution: --- → WORKSFORME
(Assignee)

Comment 6

19 years ago
I am unable to reproduce the problem in today's build.  See attached test case.
On today's Linux build I got this:

select is: [object HTMLSelectElement]
select.options is: [object HTMLCollection]
select.selectedIndex is: 0
select.options[0].value is: value1

Marking this WORKSFORME.  Thanks!

Comment 7

18 years ago
tested on win95 3-31-00 build works marking verified
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.