HTML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignHTML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 15th, 1999, 10:15 AM
monkeyboy
Guest
Dev Shed Newbie (0 - 499 posts)
 
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

Reply With Quote
  #2  
Old December 27th, 1999, 12:08 PM
time2brew
Guest
Dev Shed Newbie (0 - 499 posts)
 
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

Reply With Quote
  #3  
Old January 3rd, 2000, 10:06 PM
adashimar adashimar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2000
Location: Seattle, WA, USA
Posts: 1 adashimar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #4  
Old January 5th, 2000, 10:10 AM
monkeyboy monkeyboy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Location: london, england
Posts: 2 monkeyboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.


------------------

Reply With Quote
  #5  
Old January 5th, 2000, 10:15 AM
monkeyboy monkeyboy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Location: london, england
Posts: 2 monkeyboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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


Reply With Quote
  #6  
Old January 27th, 2000, 09:56 AM
Bjoern Bjoern is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 1999
Location: Muenster, NRW, Germany
Posts: 17 Bjoern User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
why not use the nice method typeof?

if (typeof undefined_var == "undefined")
{
....
}


Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignHTML Programming > "undefined" variables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway