I was using ‘new Option()’ to create <option>'s in a select element but every now and again we get ‘Option’ is undefined.
Undefined!
A reason to stick with the newer DOM alternatives or innerHTML.
I was using ‘new Option()’ to create <option>'s in a select element but every now and again we get ‘Option’ is undefined.
Undefined!
A reason to stick with the newer DOM alternatives or innerHTML.
A reason to stick with the newer DOM alternatives or innerHTML.
yep, that’s going to be way easier than trying to use host objects in a cross-browser manner…
the element constructor functions (Option, Form, etc.) are ancient. beyond that, they are not a part of the ECMAScript spec. even when several browser vendors all agree to implement a given host object/method (i.e. alert()), there is always the risk that they won’t be available (in a certain browser, in the future, etc.)
one solution i’ve used frequently when i have to use host objects is to “touch” them first, i.e.:
if (window.Option) {
// Global variable 'Option' is defined, probably
// 'safe-ish' to use
var option = new Option();
}
be aware though that (typeof SomeHostObjectConstructor === “function”) doesn’t always work as expected; several host objects in several browsers return wacky types. hope that helps
interesting, the screenshot I have of the error is indeed IE8.
Well I suppose a test case would be a page with this in it.
var option = new Option(‘Ex’, ‘ample’, false);
It happens rarely and I have no clue what triggers it.
My point is that ‘Option’ should always be defined.
Do you have a test case?
Here’s confirmation that it’s a known bug in IE8
http://www.eggheadcafe.com/software/aspnet/34215699/bug-in-first-page-loading.aspx