Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

testing for undefined 1

Status
Not open for further replies.

TheConeHead

Programmer
Aug 14, 2002
2,106
0
0
US
How would I test the condition of an undefined variable?

What I am doing is in an asp page I am doing:

variable1 = Request.QueryString("varName");

Now I want to use it is it is there but assign a default value if not... something like:

if (variable1 == null) {
variable1="value";
}
 
This is better suited to the ASP forum... but here's your answer, anyway... ;-)
Code:
Dim variable1
variable1 = 1 'default value
If Request.QueryString(&quot;varname&quot;) <> &quot;&quot; Then
   variable1 = Request.QueryString(&quot;varname&quot;)
End If
Hope this helps! :)
 
yeah I tried the ASP forum... no luck... as you can see (and the reason I am here, I am using JavaScript not VB) Anyway.... I converted your script to:

variable1 = 1 'default value
if (Request.QueryString(&quot;varname&quot;) != &quot;&quot;) {
variable1 = Request.QueryString(&quot;varname&quot;);
}


it does not work....
 
This works for me:

Code:
teamleader = new String(Request(&quot;teamleader&quot;))

if(teamleader==&quot;undefined&quot;)
{
    teamleader = &quot;&quot; //default value
}

Note well, the .QueryString isn't necessary (though I bet it trivially increases performance). Note also, I convert the Request explicitly to a string. I'm not sure why this solves a large number of my problems, but it does.

jared@eae.net -
 
You must omit the quotes from the code like this:
if(teamleader!=undefined)

some version of IE does not like this though, use:

if(!teamleader)
 
he has the quotes because he is converting it to a string:

teamleader = new String(Request(&quot;teamleader
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top