Detecting undefined arguments using Response.Query

Results 1 to 4 of 4

Thread: Detecting undefined arguments using Response.Query

  1. #1
    Aaron Moronez Guest

    Default Detecting undefined arguments using Response.Query

    /**<BR>Hi, I am trying to figure out the best way to detect whether a variable has been passed on the query string or not... For example, let&#039;s say I&#039;m trying to detect the parameter "bogusvar". Let&#039;s also say in this case, that it has NOT been passed:<BR>**/<BR><BR>var str1 = Request.QueryString("bogusvar");<BR><BR>// str1 should not be defined, since "bogusvar" was not passed<BR><BR>if (str1 == true) {<BR> Response.write("str1 is true (defined)");<BR>}<BR>else {<BR> if (str1 == false) {<BR> Response.write("str1 is false (undefined)");<BR> }<BR> else {<BR> Response.write("str1 is neither true nor false!");<BR> }<BR>}<BR><BR>/**<BR>Believe it or not, I get the "str1 is neither true not false!" message. How are we supposed to detect it then? The only thing I have found that works, is to force JScript to cast the value (whatever it is) into a String. In my case, it translates into "undefined", at which point I can compare against it.<BR>**/<BR><BR>var str2 = str1 + "";<BR><BR>if (str2 == "undefined")<BR> Response.write("Success!");<BR><BR>/**<BR>However, this seems kludgy at best. And god forbid anyone have a string value of "undefined" for some reason. It is also interesting to note that unless I cast str1 into a String I can perform no real operations on it!<BR>**/<BR><BR>Response.write(str1); // prints nothing<BR>Response.write(str1.toString()); // throws error<BR>Response.write("[" + str1 + "]"); // prints "[undefined]" but only because of conversion to String<BR><BR>/**<BR>Any suggestions?<BR>Thanks.<BR>**/

  2. #2
    Medieval Dude Guest

    Default RE: Detecting undefined arguments using Response.Q

    Yer overthinking it. Try this:<BR><BR>var str1 = Request.QueryString("bogusvar");<BR><BR>if (str1 == "") {<BR>Response.write("str1 is not defined");<BR>}

  3. #3
    Aaron Moronez Guest

    Default RE: Detecting undefined arguments using Response.Q

    I tried this:<BR><BR>var str1 = Request.QueryString("bogusvar");<BR><BR>if (str1 == "") { <BR> Response.write("str1 is not defined"); <BR>}<BR>else { <BR> Response.write("str is something else...");<BR>}<BR><BR>My system prints "str is something else...".<BR>Do you have an idea about what&#039;s going on?<BR>

  4. #4
    Aaron Moronez Guest

    Default Humor me, MD

    So apparently, my str1 doesn&#039;t compare to true, false, or "". It throws an error with str1.toString() AND isNan(str1). ***?<BR><BR>I might be a bad version of JSCript on the machine I&#039;m developing on... How can I check what version is installed on the machine and upgrade if necessary? (it&#039;s a sandbox I just setup to play with ASP...)<BR><BR>Humor me, what does the code from my initial post on this thread do on your system?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts