|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Hi monkeyboy:
Check out http://wsabstract.com/javatutors/determinevar.shtml ...I think it'll answer your question nicely. |
|
#4
|
|||
|
|||
|
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. ------------------ |
|
#5
|
|||
|
|||
|
<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 |
|
#6
|
|||
|
|||
|
why not use the nice method typeof?
if (typeof undefined_var == "undefined") { .... } |
![]() |
| Viewing: Dev Shed Forums > Web Design > HTML Programming > "undefined" variables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|