Closed
Bug 18319
Opened 26 years ago
Closed 26 years ago
Option Element does not retain text attribute
Categories
(Core :: DOM: Core & HTML, defect, P3)
Core
DOM: Core & HTML
Tracking
()
People
(Reporter: djoham, Assigned: vidur)
Details
Attachments
(1 file)
643 bytes,
text/html
|
Details |
When creating a new option element in javascript code, it appears that the text
attribute of the new option is not retained. See the code sample for an example.
The goal of this sample would be to have two option lists available to give the
user the ability to add and remove items from one to the other.
I was able to test this on the 8 Nov build of Mozilla on Linux.
/*Begin code sample*/
<HTML>
<BODY>
<FORM name=MyForm>
<Table border = 1>
<tr>
<td>
<select name=lstLeft id=lstLeft
style="WIDTH: 325px" multiple size=5 >
<option value=1>Left
Option 1</option>
<option value=2>Left
Option 2</option>
<option value=3>Left
Option 3</option>
<option value=4>Left
Option 4</option>
<option value=5>Left
Option 5</option>
<option value=6>Left
Option 6</option>
<option value=7>Left
Option 7</option>
<option value=8>Left
Option 8</option>
<option value=9>Left
Option 9</option>
</select>
</td>
<td>
<input type=button
onclick=MoveRight() name=cmdMoveRight id=cmdMoveRight value=">>">
<br>
<input type=button
onclick=MoveLeft() name=cmdMoveLeft id=cmdMoveLeft value="<<">
</td>
<td>
<select name=lstRight
id=lstRight style="WIDTH: 325px" size=5 multiple>
<option value=1>Right
Option 1</option>
</select>
</tr>
</table>
<input type=button name=cmdDoh id=cmdDoh value="I think
the problem is here..." onclick=cmdDohClick()>
</FORM>
</BODY>
</HTML>
<SCRIPT Language=Javascript>
function cmdDohClick() {
var newOpt = new Option;
alert("setting the value of the new option to 3")
newOpt.value = 3;
alert(newOpt.value);
alert("setting the text of the new option to Hello. Note that the text
value is not retained")
newOpt.text = "Hello"
alert(newOpt.text);
}
function MoveLeft(){
var ItemNum;
var ItemCount = document.MyForm.lstRight.length;
//Are there any selected?
if ( 0 <= document.MyForm.lstRight.selectedIndex) {
//yes there is something selected.
while ( 0 <= (ItemCount -1) ){
ItemNum = document.MyForm.lstRight.selectedIndex;
if ( 0 <= ItemNum ) {
var newOpt = new Option;
newOpt.value =
document.MyForm.lstRight[ItemNum].value;
newOpt.text =
document.MyForm.lstRight[ItemNum].text;
//now add the item to the left
document.MyForm.lstLeft.add(newOpt);
document.MyForm.lstRight.remove(ItemNum);
} // end checking for the selection of an individual
item
ItemCount--;
} // end looping through all of the item
} // end checking for any selected items in the right list
}
function MoveRight() {
var ItemNum;
var ItemCount = document.MyForm.lstLeft.length;
//Are there any selected?
if ( 0 <= document.MyForm.lstLeft.selectedIndex) {
//yes there is something selected.
while ( 0 <= (ItemCount -1) ){
ItemNum = document.MyForm.lstLeft.selectedIndex;
if ( 0 <= ItemNum ) {
var newOpt = new Option;
newOpt.value =
document.MyForm.lstLeft[ItemNum].value;
newOpt.text =
document.MyForm.lstLeft[ItemNum].text;
//now add the item to the left
document.MyForm.lstRight.add(newOpt);
document.MyForm.lstLeft.remove(ItemNum);
} // end checking for the selection of an individual
item
ItemCount--;
} // end looping through all of the item
} // end checking for any selected items in the right list
}
</SCRIPT>
Updated•26 years ago
|
Assignee: mccabe → vidur
Component: Javascript Engine → DOM Level 0
Comment 1•26 years ago
|
||
Reassigning this to the DOM component.
djoham - This bug would be just a little easier to test if you could include
your sample code as an attachment rather than in the bug itself.
Comment 2•26 years ago
|
||
Attaching simplified test case. The 'text' property of the new Option element
isn't being set when assigned to. For example:
var o = new Option("red", "1");
o.text = "green";
would still show up as "red" in a list.
Comment 3•26 years ago
|
||
Updated•26 years ago
|
Status: NEW → RESOLVED
Closed: 26 years ago
Resolution: --- → INVALID
Comment 4•26 years ago
|
||
From the DOM Level 1 spec:
http://www.w3.org/TR/REC-DOM-Level-1/level-one-html.html#ID-882764350
interface HTMLOptionElement : HTMLElement {
...
readonly attribute DOMString text;
...
Notice that text is a readonly attribute, so setting it should have no effect.
I checked in the errata, and there is no mention that this should be otherwise,
so I'm going to mark this one invalid.
Updated•26 years ago
|
Status: RESOLVED → REOPENED
OS: Linux → All
Hardware: PC → All
Updated•26 years ago
|
Status: REOPENED → RESOLVED
Closed: 26 years ago → 26 years ago
Resolution: INVALID → DUPLICATE
Comment 5•26 years ago
|
||
Okay, nevermind... I remember how this was resolved last time. Marking dup of
the existing bug.
Updated•26 years ago
|
Status: RESOLVED → VERIFIED
Comment 7•26 years ago
|
||
[bugday] verified dupe, noting that this bug is more descriptive than it's dupe.
You need to log in
before you can comment on or make changes to this bug.
Description
•