473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Bug in IIS 5.1 JScript - undefined strings from Request object

Hi All!

I have checked Windows Script help for the Undefined Data Type. It says I
should be able to do this:
// This method will work
if (typeof(x) == "undefined")
// do something

However, I have found that when I try to get something from Session and
Request that does not exist, the object coming back from each is different
when they should both be undefined.

My simple test:

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<html>
<body>
reallyNotThere: &quot;<%= Session("reallyNotThere") %>&quot;<br>
reallyNotThere2: &quot;<%= Request("reallyNotThere2") %>&quot;<br>
<%
var reallyNotThere = Session ("reallyNotThere");
Response.Write("<br>Not there &quot;" + reallyNotThere + "&quot;")
if (typeof(reallyNotThere) == "undefined")
{
Response.Write("<br>it is not there!");
}
else
{
Response.Write("<br>it is there");
}

var reallyNotThere2 = Request("reallyNotThere2");
Response.Write("<br>Not there 2 &quot;" + reallyNotThere2 +
"&quot;")
if (typeof(reallyNotThere2) == "undefined")
{
Response.Write("<br>it is not there!");
}
else
{
Response.Write("<br>it is there");
}
%>
</body>
</html>
The output:

reallyNotThere: ""
reallyNotThere2: ""

Not there "undefined"
it is not there!
Not there 2 "undefined"
it is there

If
(typeof(reallyNotThere) == "undefined")
is true, so should
(typeof(reallyNotThere2) == "undefined")

Rob
:)
Jul 20 '05 #1
4 3163
I think the difference is that Session("reallyNotThere") returns null
and Request("reallyNotThere2") returns an empty string.

Try Response.Write(typeof(reallyNotThere) + " - " +
typeof(reallyNotThere2)), if I am correct it should display "undefined
- object".

-Wagner

"Robert Mark Bram" <re********@removethis.optushome.com.au> wrote in message news:<3f***********************@news.optusnet.com. au>...
Hi All!

I have checked Windows Script help for the Undefined Data Type. It says I
should be able to do this:
// This method will work
if (typeof(x) == "undefined")
// do something

However, I have found that when I try to get something from Session and
Request that does not exist, the object coming back from each is different
when they should both be undefined.

My simple test:

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<html>
<body>
reallyNotThere: &quot;<%= Session("reallyNotThere") %>&quot;<br>
reallyNotThere2: &quot;<%= Request("reallyNotThere2") %>&quot;<br>
<%
var reallyNotThere = Session ("reallyNotThere");
Response.Write("<br>Not there &quot;" + reallyNotThere + "&quot;")
if (typeof(reallyNotThere) == "undefined")
{
Response.Write("<br>it is not there!");
}
else
{
Response.Write("<br>it is there");
}

var reallyNotThere2 = Request("reallyNotThere2");
Response.Write("<br>Not there 2 &quot;" + reallyNotThere2 +
"&quot;")
if (typeof(reallyNotThere2) == "undefined")
{
Response.Write("<br>it is not there!");
}
else
{
Response.Write("<br>it is there");
}
%>
</body>
</html>
The output:

reallyNotThere: ""
reallyNotThere2: ""

Not there "undefined"
it is not there!
Not there 2 "undefined"
it is there

If
(typeof(reallyNotThere) == "undefined")
is true, so should
(typeof(reallyNotThere2) == "undefined")

Rob
:)

Jul 20 '05 #2
Hi Wagner,
I think the difference is that Session("reallyNotThere") returns null
and Request("reallyNotThere2") returns an empty string.

Try Response.Write(typeof(reallyNotThere) + " - " +
typeof(reallyNotThere2)), if I am correct it should display "undefined
- object".


Not quite - reallyNotThere2 is an object (with no toString method!) that
becomes the String "undefined" when you put in a String.

It seems an impossible test - it doesn't report itself as being null or
undefined plus it's not an empty String.. meaning there is no easy way to
tell whether it is "undefined" because it's not defined or "undefined"
because the user typed that... except if you test for this:
if ("toString" in reallyNotThere2)

I tried this:

var reallyNotThere = Session("reallyNotThere") ;
var reallyNotThere2 = Request("reallyNotThere") ;

Response.Write("=========<br>"),
Response.Write("reallyNotThere== null - " + (reallyNotThere == null ) +
"<br>");
Response.Write("reallyNotThere === null - " + (reallyNotThere === null ) +
"<br>");
Response.Write("reallyNotThere2 == \"\" - " + (reallyNotThere2 == "" ) +
"<br>");
Response.Write("reallyNotThere2 === \"\" - " + (reallyNotThere2 === "" ) +
"<br>");
Response.Write("reallyNotThere2 == null - " + (reallyNotThere2 == null ) +
"<br>");
Response.Write("reallyNotThere2 === null - " + (reallyNotThere2 === null )
+ "<br>");
Response.Write(typeof(reallyNotThere) + " - " + typeof(reallyNotThere2)+
"<br>"),
Response.Write("reallyNotThere is \"" + reallyNotThere + "\" - " +
"reallyNotThere2 is \"" + reallyNotThere2 + "\"<br>");
if ("toString" in reallyNotThere2) {
Response.Write("reallyNotThere2 has a toString<br>");
} else {
Response.Write("reallyNotThere2 has no toString<br>");
}
Response.Write("=========<br>");


Output:
=========
reallyNotThere== null - true
reallyNotThere === null - false
reallyNotThere2 == "" - false
reallyNotThere2 === "" - false
reallyNotThere2 == null - false
reallyNotThere2 === null - false
undefined - object
reallyNotThere is "undefined" - reallyNotThere2 is "undefined"
reallyNotThere2 has no toString
=========

Rob
:)
Jul 20 '05 #3
On Sat, 18 Oct 2003 07:45:05 +1000, "Robert Mark Bram"
<re********@removethis.optushome.com.au> wrote:
Hi Wagner,
I think the difference is that Session("reallyNotThere") returns null
and Request("reallyNotThere2") returns an empty string.

Try Response.Write(typeof(reallyNotThere) + " - " +
typeof(reallyNotThere2)), if I am correct it should display "undefined
- object".


Not quite - reallyNotThere2 is an object (with no toString method!) that
becomes the String "undefined" when you put in a String.

It seems an impossible test - it doesn't report itself as being null or
undefined plus it's not an empty String.. meaning there is no easy way to
tell whether it is "undefined" because it's not defined or "undefined"
because the user typed that... except if you test for this:
if ("toString" in reallyNotThere2)

I tried this:

var reallyNotThere = Session("reallyNotThere") ;
var reallyNotThere2 = Request("reallyNotThere") ;


I usually do this:
var reallyNotThere2 = String(Request("reallyNotThere"));
if (reallyNotThere2 == "" || reallyNotThere2 == "undefined")
reallyNotThere2 = null;
and then test for null where appropriate.

Regards,
Steve
Jul 20 '05 #4
Hi Steve!
I usually do this:
var reallyNotThere2 = String(Request("reallyNotThere"));
if (reallyNotThere2 == "" || reallyNotThere2 == "undefined")
reallyNotThere2 = null;
and then test for null where appropriate.


I don't like to use this because of the (admittedly remote) possibility that
I have a text field where "undefined" is a possible value... but I see your
point.

Rob
:)
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Robert Mark Bram | last post by:
Hi All! I have checked Windows Script help for the Undefined Data Type. It says I should be able to do this: // This method will work if (typeof(x) == "undefined") // do something However,...
3
by: Christopher Brandsdal | last post by:
Hi! Maby this is wring newsgroup.. I'm using ASP / VBscript on my own cms system, but I needed to use some jscript to make something work... I'm new to jscript, so here is a simple question:...
6
by: Dan Roberts | last post by:
I am running some off-the-shelf software that is written in ASP, which uses JScript to generate dynamic content within HTML forms. There are several ASP pages which are partially rendering to IE,...
3
by: Larry David | last post by:
Hi, I'm just trying to wrap my mind around the ASP.NET model. Let me walk you through a trivial scenario: Let's say I have a form containing a text box where the user enters his name. It also...
4
by: RFS666 | last post by:
Hello, I have the following problem: I have a web project where I display an activeX control that displays 2D-graphs on an aspx-page. I use jscript to access and modify the properties of the...
6
by: RFS666 | last post by:
Hello, After I posted yesterday "using C# class in jscript", I have a new problem: I have a C# class - DBResult - that contains (and other variables) a string array (and other variables), that...
2
by: JNariss | last post by:
Hello, I have created a connection to one of my databases using DreamWeaver and created a form. When I go to preview the form in a browser I can see it and fill out fields. However when I click...
1
by: JNariss | last post by:
Hello, I have created a connection to my Access database with Dreamweaver and made a simple form with 4 fields. The code behind this form was/is: <%@LANGUAGE="VBCRIPT" CODEPAGE="1252"%>...
2
by: Jayme Pechan | last post by:
I migrated a formerly C++ COM component to C# and I have been able to duplicate all the old behavior except for one. I have an enumeration property that returns a list of com objects. Using the...
1
by: Andrew Wan | last post by:
How can VBScript code access JScript code variables in the same ASP page? <SCRIPT LANGAUGE="VBScript"> Dim a a = 10 </SCRIPT> <SCRIPT LANGUAGE="JScript"> Response.Write(a); </SCRIPT>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.