Closed Bug 8431 Opened 26 years ago Closed 26 years ago

Cannot update <SELECT> combo boxes with JS

Categories

(Core :: DOM: Core & HTML, defect, P3)

x86
Linux
defect

Tracking

()

VERIFIED INVALID

People

(Reporter: alecf, Assigned: pollmann)

References

Details

I have code that does this: var opt = document.createElementWithNameSpace("OPTION", "http://www.w3.org/TR/REC-html40"); opt.text = "mytext"; opt.value = "somevalue"; while (selWidget.length != 0) { selWidget.remove(0); } selWidget.add(opt) But I just get blank text in my combo box. This is on all platforms with native widgets.
Blocks: 8422
Assignee: joki → vidur
This is vidur's, I think. Or maybe pollmann
Assignee: vidur → pollmann
It's Eric's.
Status: NEW → RESOLVED
Closed: 26 years ago
Resolution: --- → INVALID
The text attribute of an option is readonly. Thus, your option will have blank text. Here's a way to work around your problem: var opt = new Option("mytext","somevalue"); while (selWidget.length != 0) { selWidget.remove(0); } selWidget.add(opt)
I found this information at: http://www.w3.org/TR/REC-DOM-Level-1/level-one-html.html Which says: interface HTMLOptionElement : HTMLElement { readonly attribute HTMLFormElement form; attribute boolean defaultSelected; *--------> readonly attribute DOMString text; <--------* attribute long index; attribute boolean disabled; attribute DOMString label; readonly attribute boolean selected; attribute DOMString value; };
Status: RESOLVED → VERIFIED
oh... how silly. That means you can't create option elements with document.createElementWithNamespace() Oh well, thanks.
FYI, I think the DOM way to do this would be to replace opt.text = "mytext"; with opt.appendChild(document.createTextNode("mytext")); (If it already has text, you would need replaceChild.)
ah...good to know. Thanks.
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.