Problem with 'undefined' object In server side JavaScript

O

Ophir

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.Redirect method from the page checking the
submition.
When I do that I call the page with a parameter like this
Response.Redirect("Page.asp?FROM=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.QueryString("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????
 
M

McKirahan

Ophir said:
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.Redirect method from the page checking the
submition.
When I do that I call the page with a parameter like this
Response.Redirect("Page.asp?FROM=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.QueryString("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????

How about:

var from_flag = "";
if (Request.QueryString() != "") {
from_flag = Request.QueryString("FROM");
}


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

Ophir

McKirahan said:
How about:

var from_flag = "";
if (Request.QueryString() != "") {
from_flag = Request.QueryString("FROM");
}


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

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("FROM"))

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top