The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> HTML Programming
|
"undefined" variables
Discuss "undefined" variables in the HTML Programming forum on Dev Shed. "undefined" variables HTML Programming forum covering discussions of HTML and XHTML, as well as HTML-related issues such as writing W3C Compliant code. Use HyperText Markup Language for building websites.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 15th, 1999, 10:15 AM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
hi,
i've been struggling with a little problem, i'd be very grateful for a straw to clutch at :-)
basically, i need to test a variable to see if it is undefined. i can test for NotaNumber easy enuf, but undefined is tricky.
the variable is compID, and if it is undefined, compID.length = 9 (9 letters in "undefined"!!! i was hoping it would be 0). however, comparing compID to "undefined" comes up false.
can anybody help a frazzled newbie web bloke?
cheers.
MonkeyBoy
|

December 27th, 1999, 12:08 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
The easiest thing to do I think is to set compID="testvalue" when you var it.
var compID="undefined";
or someother value that you know it will never get set to. Then you can test for that value
|

January 3rd, 2000, 10:06 PM
|
|
Junior Member
|
|
Join Date: Jan 2000
Location: Seattle, WA, USA
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Hi monkeyboy:
Check out http://wsabstract.com/javatutors/determinevar.shtml ...I think it'll answer your question nicely.
|

January 5th, 2000, 10:10 AM
|
|
Registered User
|
|
Join Date: Dec 1999
Location: london, england
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
thanks, time2brew.
unfortunately, i had to read the variable off the requesting URL using Request.QueryString, which meant that even if I had set up var compID with an initial value, it still comes back as undefined if there is no variable in the URL.
i case anyone is following this thread... :-))) ... i used a workaround which was to create a new string object with the value assigned as follows:
tempID = new String(Request.QueryString("compID")); // store as a string, so undefined = "undefined"
if (tempID == "undefined"){ //if no compID in URL
Session("Udata").newuser = 0;
}
else Session("Udata").newuser = 1;
the above nonsense actually stores the value of the variable retrieved from the URL request as the string "undefined", which can then be tested for.
phew!
bet there's a better way!!!!
thanks anyway, brew master!.
monkeyboy.
------------------
|

January 5th, 2000, 10:15 AM
|
|
Registered User
|
|
Join Date: Dec 1999
Location: london, england
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by adashimar:
Hi monkeyboy:
Check out http://wsabstract.com/javatutors/determinevar.shtml ...I think it'll answer your question nicely.[/quote]
cool!
thanks adashimar, i think that might work a little more neatly than my solution... :-))
monkeyboy
|

January 27th, 2000, 09:56 AM
|
|
Registered User
|
|
Join Date: Aug 1999
Location: Muenster, NRW, Germany
Posts: 17
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
why not use the nice method typeof?
if (typeof undefined_var == "undefined")
{
....
}
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|