Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    cant test undefined QueryString (small test included)

    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...

    PHP Code:
    <%@LANGUAGE="JAVASCRIPT"%>

    <
    html>
    <
    head>
    <
    title>scheduler</title>
    </
    head>
    <
    body>


    <
    form>

      
    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"); } %>"/>
      <
    br/>
        <% 
      
       
    //
       
    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"); 
       
       
    //*/  
      
    %>

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

    </
    form>

    </
    body>
    </
    html

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    478
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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":

    Code:
    <%
    If Request.QueryString("var1") = "" Then
     Response.Write "It's a zero length string"
    End If
    %>
    J. Paul Schmidt
    www.Bullschmidt.com - Freelance Web and Database Developer
    www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips

  • #3
    Regular Coder
    Join Date
    Sep 2004
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This might help you.
    http://www.devguru.com/technologies/...ript/11465.asp
    Code:
    pet = "Rachel has 312 baby aardvarks" 
    CheckNum = parseInt(pet) 
    if(isNaN(CheckNum)) 
      { 
        document.write("<BR>Sorry, CheckNum is a NaN") 
        document.write("<BR>Left-most character = " + pet.substring(0,1)) 
      }
    Code:
    OUTPUT:
    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

  • #4
    New Coder
    Join Date
    Aug 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanx

    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.

  • #5
    Regular Coder
    Join Date
    Sep 2004
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Code:
    ="<% 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.


  •  

    Posting Permissions

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