Closed Bug 61628 Opened 24 years ago Closed 23 years ago

new Option().selected = true causes error

Categories

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

x86
Other
defect

Tracking

()

RESOLVED FIXED
Future

People

(Reporter: martin.honnen, Assigned: rods)

References

()

Details

(Keywords: dom0, relnote)

Attachments

(2 files)

When I create an option with var option = new Option(); and then try to set the selected property e.g. option.selected = true; M18 shows an error in the JavaScript console. That is DOM level 0 stuff that should work
This patch fixes the exception but this still doesn't make mozilla work as expected, me thinks. Rods, could you look into this? Can we use the pres state or some such here? Or do we even wanto make this work?
Assignee: jst → rods
My guess is that this is patch: Index: nsHTMLOptionElement.cpp =================================================================== RCS file: /cvsroot/mozilla/layout/html/content/src/nsHTMLOptionElement.cpp,v retrieving revision 1.60 diff -u -r1.60 nsHTMLOptionElement.cpp --- nsHTMLOptionElement.cpp 2000/12/23 10:56:19 1.60 +++ nsHTMLOptionElement.cpp 2001/01/08 14:21:55 @@ -281,7 +281,7 @@ } } - return result; + return NS_OK; } //NS_IMPL_BOOL_ATTR(nsHTMLOptionElement, DefaultSelected, defaultselected)
Status: NEW → ASSIGNED
The problem that this example illustrates is: 1) there are no frames, so it must cache it in the presstate 2) but options use their parent's presstate and this option doesn't have a parent yet. I could either cache the value locally or the presstate locally, but that isn't very desriable Now here is something intersting, if I change the example to: var select = document.createElement("SELECT") var option = new Option(); select.appendChild(option); option.selected = true; var val = option.selected; dump(val); In this example, the option does have a parent (the select), but the select hasn't been added to a document or there isn't a document, because when it calls nsGenericHTMLElement::GetPrimaryPresState to get the prestate, the document pointer is null in the content.
Rods, you're right, that's pretty much what my patch did, sorry about not including it here :-) This is yet one more reason for us to fix the buggy ownerDocument in mozilla, if that would work correctly you could call GetOwnerDocument() (or GetDocument() could possibly do that for you) and you would get the document even if the element is not really part of a document yet/any more. If this worked you could get at the pres state in the document at all times as long as the element doesn't outlive it's document.
Keywords: dom0
Setting milestone to future. Added relnote keyword. See Rods descripion of a work around.
Keywords: relnote
Target Milestone: --- → Future
I'll attach a test case in a moment for a similar problem. Could someone have a look, and see if it is the same problem, or something different -- in which case I'll open a new bug. With recent Mozilla builds (e.g. 20010709), there is a problem on the Bugzilla Query page, where if you: a) select a product and a component, and do a reload b) select a product and a component, do the query, and hit 'Back' c) select a product and a component, do the query, and hit 'Edit this query' then the Component you selected is no longer selected. The symptoms are similar to bug#72379, but I believe the cause is different. The Javascript on the Bugzilla Query page, and the Javascript in my test case both delete the items from a SELECT, add some more in, and try and select one. But nothing gets selected :(
Note that clicking the select button in my test case will start doing some reloading -- oops -- it doesn't do that if you save the attachment locally, but that's not the important bit of the testcase anyway .
Is the same as, or related to bug#86659, which is also todo with javascript selecting options?
I'm not getting an error on 0.9.4; but it still shows as false. The fix to bug 34297 actually sets it to true, and doesn't show an error.
Fixed with bug 34297.
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: