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)
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.
Updated•26 years ago
|
Assignee: joki → vidur
Comment 1•26 years ago
|
||
This is vidur's, I think. Or maybe pollmann
Updated•26 years ago
|
Assignee: vidur → pollmann
Comment 2•26 years ago
|
||
It's Eric's.
Assignee | ||
Updated•26 years ago
|
Status: NEW → RESOLVED
Closed: 26 years ago
Resolution: --- → INVALID
Assignee | ||
Comment 3•26 years ago
|
||
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)
Assignee | ||
Comment 4•26 years ago
|
||
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;
};
Reporter | ||
Updated•26 years ago
|
Status: RESOLVED → VERIFIED
Reporter | ||
Comment 5•26 years ago
|
||
oh... how silly. That means you can't create option elements with
document.createElementWithNamespace()
Oh well, thanks.
Comment 6•26 years ago
|
||
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.)
Reporter | ||
Comment 7•26 years ago
|
||
ah...good to know. Thanks.
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•