0

Good Day all

i am reluctantly maintaining a Classic Asp application that will be re-written in few months to come. i have an issue where i have a Code like this

   if(document.frmEntry.optMethod != "undefined")
                        {
                            if (document.frmEntry.optMethod.selectedIndex == 0) {
                                strPrompt=strPrompt+'Please specify the Valuation Method\n';
                                if ( objFocus == null ) {
                                    objFocus = document.frmEntry.optMethod;
                                }
                            }
                        } 

my problem here is that even if document.frmEntry.optMethod is not equal to undefined the code still go into the condition as if it was true. i have attached a proof in my debuger.

http://www.vetauinvest.com/Example/IE_DEBUGGER.png

Thanks

Edited by vuyiswamb: remove some tag

4
Contributors
5
Replies
17
Views
3 Years
Discussion Span
Last Post by Airshow
0

Your problem is simple... if(document.frmEntry.optMethod != "undefined") this is testing if an object, that may not exist (undefined) is different than an string with value "undefined".

Two ways to resolve it:

if( typeof document.frmEntry.optMethod != "undefined" )

OR

if(document.frmEntry.optMethod != undefined )
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.