Closed Bug 20028 Opened 20 years ago Closed 20 years ago

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

Categories

(Core :: Layout: Form Controls, defect, P3)

x86
Windows 95
defect

Tracking

()

VERIFIED WORKSFORME

People

(Reporter: bugs, Assigned: pollmann)

References

Details

Attachments

(1 file)

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. ***
Assignee: karnaze → pollmann
Reassigning to Eric.
QA Contact update.
Status: NEW → ASSIGNED
Target Milestone: M14
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
Attached file test case
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → WORKSFORME
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!
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.