#1
  1. No Profile Picture
    monkeyboy
    Guest
    Devshed Newbie (0 - 499 posts)
    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
  2. #2
  3. No Profile Picture
    time2brew
    Guest
    Devshed Newbie (0 - 499 posts)
    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
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Seattle, WA, USA
    Posts
    1
    Rep Power
    0
    Hi monkeyboy:
    Check out http://wsabstract.com/javatutors/determinevar.shtml ...I think it'll answer your question nicely.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Location
    london, england
    Posts
    2
    Rep 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.


    ------------------
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Location
    london, england
    Posts
    2
    Rep 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

  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 1999
    Location
    Muenster, NRW, Germany
    Posts
    17
    Rep Power
    0
    why not use the nice method typeof?

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

Similar Threads

  1. Replies: 2
    Last Post: February 10th, 2004, 11:03 PM
  2. sending variables to active flash movie
    By spdevshed in forum Flash Help
    Replies: 0
    Last Post: May 10th, 2003, 06:34 PM
  3. Automatically register all variables Global
    By dreamstring in forum PHP Development
    Replies: 1
    Last Post: February 19th, 2003, 06:07 AM
  4. Persistant variables - Application variables
    By murali in forum PHP Development
    Replies: 25
    Last Post: July 2nd, 2002, 06:43 AM
  5. passing variables problems with $PHP_SELF
    By BicyclePunk in forum PHP Development
    Replies: 17
    Last Post: November 10th, 2001, 11:21 AM

IMN logo majestic logo threadwatch logo seochat tools logo