View Full Version : cant test undefined QueryString (small test included)

08-23-2005, 09:28 PM
Hello all,
I had a lil question i hope one of you can answer...
i have a textfield that when you first goto the page, since the query string isnt made yet (value undefined), it fills in a default value like 0.

now i try testing for undefined which is what its says it is yet it tests true for != undefined, even though again it outputs undefined.... any ideas guys?

thanx in advance...




Should be 0 when 1st goto page but get '1.#QNAN' instead...
<input type="text" name="attendeesNum" size="20" value="<% if( Request.QueryString("attendeesNum")!="undefined" ){ Response.write(parseInt(Request.QueryString("attendeesNum"))) }else{ Response.write("0"); } %>"/>

Response.Write( "QueryString value should output undefined=... <i>"+ Request.QueryString("attendeesNum") +"</i> Good"+"\n");

//Response.Write( "<br><b>"+(Request.QueryString("attendeesNum")!= "") +"</b>"+"\n");
//Response.Write( "<br><b>"+(Request.QueryString("attendeesNum")!= null) +"</b>"+"\n");

Response.Write( "<br>Is QueryString value whenn tested in if statement undefined though? (should be TRUE)<b>"+(Request.QueryString("attendeesNum")== "undefined" ) +"</b>"+"\n");


<input type="submit" value="submit" />



08-23-2005, 11:15 PM
It's a zero length string (i.e. ""), and you can test with this on a page and use no querystring when opening the page and you should see the text, "It's a zero length string":

If Request.QueryString("var1") = "" Then
Response.Write "It's a zero length string"
End If

08-24-2005, 04:00 PM
This might help you.

pet = "Rachel has 312 baby aardvarks"
CheckNum = parseInt(pet)
document.write("<BR>Sorry, CheckNum is a NaN")
document.write("<BR>Left-most character = " + pet.substring(0,1))

Sorry, CheckNum is a NaN
Left-most character = R
Explanation: You can use the isNaN function to see if the returned value is a NaN.
*NaN = Not a Number

08-24-2005, 08:58 PM
ahhh yay! parseInt and NaN solution worked. The check for a 0 length string did not work unless u posted, not when u arrive to the page which is what i wanted, not sure why.
but thanx again.

08-24-2005, 10:08 PM
I don't think you can check for "undefined" state in Javascript, it's more of an error message. Although it seems to me that you could have done this as well.

="<% if( Request.QueryString("attendeesNum")!="" ){ Response.write(parseInt(Request.QueryString("attendeesNum"))) }else{ Response.write("0"); } %>"
That should check for an empty string (as in the first time you hit the page). Not sure though, I don't use server side Javascript only client-side.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum