Problem with 'undefined' object In server side JavaScript

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

    Problem with 'undefined' object In server side JavaScript

    Hello all

    I have this problem:
    I'm displaying a loggin page.
    If the user entered an invalid UserName/Password I display the page
    again.
    When this happens I want to give the user a different message then the
    one
    displayed when the page was initially displayed.

    I use the Response.Redire ct method from the page checking the
    submition.
    When I do that I call the page with a parameter like this
    Response.Redire ct("Page.asp?FR OM=1").

    When I get the parameter in the page I know I need to show a different
    message.

    The problem is that if the page is called without the parameter, I
    cannot determine that the parameter is missing.


    The codse is very simple:

    from_flag = Request.QuerySt ring("FROM")

    Now is the problem -
    if I use if(from_flag == 'undefined') - this condition return
    false.
    but if I display from_flag using Response.Write( from_flag) I get
    "undefined"

    if I use if(typeof from_flag == "undefined" ) - this does not work
    since the typeof return "object" in both cases when I call the page
    with the parameter or without the parameter.

    also I tried to comnpare with null does not work.

    By the way if I use VBScript as the script lang - it works fine I
    just need to compare the from_flag with vbNullString and all is well.

    How can I do it in JavaScript????
  • McKirahan

    #2
    Re: Problem with 'undefined' object In server side JavaScript

    "Ophir" <ophirbb@netvis ion.net.il> wrote in message
    news:ec2c754d.0 411120351.64a23 c58@posting.goo gle.com...[color=blue]
    > Hello all
    >
    > I have this problem:
    > I'm displaying a loggin page.
    > If the user entered an invalid UserName/Password I display the page
    > again.
    > When this happens I want to give the user a different message then the
    > one
    > displayed when the page was initially displayed.
    >
    > I use the Response.Redire ct method from the page checking the
    > submition.
    > When I do that I call the page with a parameter like this
    > Response.Redire ct("Page.asp?FR OM=1").
    >
    > When I get the parameter in the page I know I need to show a different
    > message.
    >
    > The problem is that if the page is called without the parameter, I
    > cannot determine that the parameter is missing.
    >
    >
    > The codse is very simple:
    >
    > from_flag = Request.QuerySt ring("FROM")
    >
    > Now is the problem -
    > if I use if(from_flag == 'undefined') - this condition return
    > false.
    > but if I display from_flag using Response.Write( from_flag) I get
    > "undefined"
    >
    > if I use if(typeof from_flag == "undefined" ) - this does not work
    > since the typeof return "object" in both cases when I call the page
    > with the parameter or without the parameter.
    >
    > also I tried to comnpare with null does not work.
    >
    > By the way if I use VBScript as the script lang - it works fine I
    > just need to compare the from_flag with vbNullString and all is well.
    >
    > How can I do it in JavaScript????[/color]

    How about:

    var from_flag = "";
    if (Request.QueryS tring() != "") {
    from_flag = Request.QuerySt ring("FROM");
    }


    (The above is pseudo code; I use VBScript for my ASP.)


    Comment

    • Ophir

      #3
      Re: Problem with 'undefined' object In server side JavaScript

      "McKirahan" <News@McKirahan .com> wrote in message news:<g32ld.602 872$8_6.435612@ attbi_s04>...
      [color=blue]
      >
      > How about:
      >
      > var from_flag = "";
      > if (Request.QueryS tring() != "") {
      > from_flag = Request.QuerySt ring("FROM");
      > }
      >
      >
      > (The above is pseudo code; I use VBScript for my ASP.)[/color]

      McKirahan thanks fore the reply
      Your idea will not solve the problem, because if the QueryString will
      not contain a "FROM" parameter but something else I will have to ask
      later for the value of from_flag and again will be in the same
      problem.

      How ever I have found out that this solved the problem:

      var from_flag = new String(Request. QueryString("FR OM"))

      if (from_flag == "undefined" )
      {
      Do Somthing
      }

      This code works and if there is no FROM parameter passed to the page
      from_flag gets to be undefined and the if works fine.

      Thanks again
      Ophir

      Comment

      Working...