undefined var

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Karsten

    undefined var

    Hi

    I don't get this, could anyone help me out here, thanks :)

    When I load this page, I always gets the "wrong" alert and password is
    undefined, but how do I detect this in the code?
    Checking if password is "" undefined or "undefined" seems to work.


    -----------something.asp---------------
    <%@ language="javas cript" %>
    <html>
    <body>
    <%
    var password = Request.Form("p assword");
    if (password == "") Response.Write( "ZZZZZZZZZZ ");
    if (password == undefined) Response.Write( "ZZZZZZZZZZ ");
    if (password == "undefined" ) Response.Write( "ZZZZZZZZZZ ");

    if (password == "secret")
    Response.Write( "<script>alert( 'ok')</script>");
    else if (password !== "")
    Response.Write( "<script>alert( 'wrong.')</script>");
    Response.Write( "entered="+pass word)
    %>
    </body>
    </html>



  • joker

    #2
    Re: undefined var

    You forgot to enter the "{" & "}" in your if statements.

    Karsten wrote:
    [color=blue]
    > Hi
    >
    > I don't get this, could anyone help me out here, thanks :)
    >
    > When I load this page, I always gets the "wrong" alert and password is
    > undefined, but how do I detect this in the code?
    > Checking if password is "" undefined or "undefined" seems to work.
    >
    >
    > -----------something.asp---------------
    > <%@ language="javas cript" %>
    > <html>
    > <body>
    > <%
    > var password = Request.Form("p assword");
    > if (password == "") Response.Write( "ZZZZZZZZZZ ");
    > if (password == undefined) Response.Write( "ZZZZZZZZZZ ");
    > if (password == "undefined" ) Response.Write( "ZZZZZZZZZZ ");
    >
    > if (password == "secret")
    > Response.Write( "<script>alert( 'ok')</script>");
    > else if (password !== "")
    > Response.Write( "<script>alert( 'wrong.')</script>");
    > Response.Write( "entered="+pass word)
    > %>
    > </body>
    > </html>
    >
    >
    >[/color]

    Comment

    • Evertjan.

      #3
      Re: undefined var

      Karsten wrote on 12 sep 2004 in microsoft.publi c.inetserver.as p.general:
      [color=blue]
      > var password = Request.Form("p assword");
      > if (password == "") Response.Write( "ZZZZZZZZZZ ");
      > if (password == undefined) Response.Write( "ZZZZZZZZZZ ");
      > if (password == "undefined" ) Response.Write( "ZZZZZZZZZZ ");
      >[/color]

      A Request.Form() of a name not post-submitted is
      always an empty string, never undefined.

      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress,
      but let us keep the discussions in the newsgroup)

      Comment

      • The Mighty Chaffinch

        #4
        Re: undefined var

        > I don't get this, could anyone help me out here, thanks :)[color=blue]
        >
        > When I load this page, I always gets the "wrong" alert and password is
        > undefined, but how do I detect this in the code?
        > Checking if password is "" undefined or "undefined" seems to work.
        >
        >
        > -----------something.asp---------------
        > <%@ language="javas cript" %>
        > <html>
        > <body>
        > <%
        > var password = Request.Form("p assword");
        > if (password == "") Response.Write( "ZZZZZZZZZZ ");
        > if (password == undefined) Response.Write( "ZZZZZZZZZZ ");[/color]

        I don't understand the line above - is undefined a variable you set up
        somewhere else? Could this be your undefined var?
        [color=blue]
        > if (password == "undefined" ) Response.Write( "ZZZZZZZZZZ ");
        >
        > if (password == "secret")
        > Response.Write( "<script>alert( 'ok')</script>");
        > else if (password !== "")
        > Response.Write( "<script>alert( 'wrong.')</script>");
        > Response.Write( "entered="+pass word)
        > %>
        > </body>
        > </html>[/color]

        I use code like this for fields that may be blank:

        var dob = (String (Request.Form.I tem("dob")) == "")
        ? null
        : String (Request.Form.I tem("dob"));

        This gives the string value or null if it wasn't entered by the user. But if
        your password field is mandatory at the client end then this should work:

        var password = String (Request.Form.I tem("password") );

        You should only get "undefined" if the field is not present in the HTTP
        Request, not if it's present but blank It should be defined in the HTML as
        <INPUT NAME = "password" ...>.

        If security is an important consideration perhaps you should encode the
        password before sending it using MD5 or something similar. Then *don't* use
        "NAME =" on the password field itself so it doesn't get submitted:

        <INPUT ID = "password" TYPE = "password" ...>
        <INPUT NAME = "encoded_pw d" TYPE = "hidden">

        BUT note that JScript doesn't like strings containing binary codes like MD5
        so you need to represent it in encoded_pwd as something like "df9e98f96a ..."
        then all should be well. Works for me anyway.

        Hope this is some help.

        MC


        Comment

        • Karsten

          #5
          Re: undefined var

          Thanks! :)


          Comment

          Working...