[Javascript] I can test for undefined...using typeof or === or == please help

TomMallard mallard at serv.net
Sat Aug 11 09:26:46 CDT 2001


This syntax should work....

if (typeof(mydropdown.options[0]) == 'undefined'){...do something...}

If mydropdown.options[0] isn't an object you can't get a property. You may
be getting this error if the code is parsed before the select box is done
being written (timing error). Place the code after the select box it
references or fire it with the onload event from the body tag if that's what
is happening.

tom mallard
seattle
----- Original Message -----
From: "Scott.Wiseman" <swiseman at remax-cahi.com>
To: <javascript at LaTech.edu>
Sent: Friday, August 10, 2001 6:20 PM
Subject: [Javascript] I can test for undefined...using typeof or === or ==
please help


> non of these if statements catch the undefined
>
> but the alert reports 0 undefined.
> so what's up.... is there a type???
>
>
> here is the code:
>
>
>  alert("0 "+mydropdown.options[0].value);
>    if(typeof mydropdown.options[0].value == undefined)
>    {
>     alert("found 1")
>     myvalue1 = NULL;
>    }
>    if(typeof mydropdown.options[0].value == undefined)
>    {
>     alert("found x 1")
>    }
>    if(typeof mydropdown.options[0].value === undefined)
>    {
>     alert("found x 2")
>    }
>    if(mydropdown.options[0].value == undefined)
>    {
>     alert("found x 3")
>    }
>
>    if(typeof mydropdown.options[0].value != undefined ||
> mydropdown.options[0].value != "unde" )
>    {
>     myvalue1 = mydropdown.options[0].value;
>    }
>




More information about the Javascript mailing list