473,569 Members | 2,760 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="JA VASCRIPT" CODEPAGE="65001 "%>
<html>
<body>
reallyNotThere: &quot;<%= Session("really NotThere") %>&quot;<br>
reallyNotThere2 : &quot;<%= Request("really NotThere2") %>&quot;<br>
<%
var reallyNotThere = Session ("reallyNotTher e");
Response.Write( "<br>Not there &quot;" + reallyNotThere + "&quot;")
if (typeof(reallyN otThere) == "undefined" )
{
Response.Write( "<br>it is not there!");
}
else
{
Response.Write( "<br>it is there");
}

var reallyNotThere2 = Request("really NotThere2");
Response.Write( "<br>Not there 2 &quot;" + reallyNotThere2 +
"&quot;")
if (typeof(reallyN otThere2) == "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(reallyN otThere) == "undefined" )
is true, so should
(typeof(reallyN otThere2) == "undefined" )

Rob
:)
Jul 20 '05 #1
4 3165
I think the difference is that Session("really NotThere") returns null
and Request("really NotThere2") returns an empty string.

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

-Wagner

"Robert Mark Bram" <re********@rem ovethis.optusho me.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="JA VASCRIPT" CODEPAGE="65001 "%>
<html>
<body>
reallyNotThere: &quot;<%= Session("really NotThere") %>&quot;<br>
reallyNotThere2 : &quot;<%= Request("really NotThere2") %>&quot;<br>
<%
var reallyNotThere = Session ("reallyNotTher e");
Response.Write( "<br>Not there &quot;" + reallyNotThere + "&quot;")
if (typeof(reallyN otThere) == "undefined" )
{
Response.Write( "<br>it is not there!");
}
else
{
Response.Write( "<br>it is there");
}

var reallyNotThere2 = Request("really NotThere2");
Response.Write( "<br>Not there 2 &quot;" + reallyNotThere2 +
"&quot;")
if (typeof(reallyN otThere2) == "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(reallyN otThere) == "undefined" )
is true, so should
(typeof(reallyN otThere2) == "undefined" )

Rob
:)

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

Try Response.Write( typeof(reallyNo tThere) + " - " +
typeof(reallyNo tThere2)), 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("really NotThere") ;
var reallyNotThere2 = Request("really NotThere") ;

Response.Write( "=========<br>" ),
Response.Write( "reallyNotThere == null - " + (reallyNotThere == null ) +
"<br>");
Response.Write( "reallyNotT here === null - " + (reallyNotThere === null ) +
"<br>");
Response.Write( "reallyNotThere 2 == \"\" - " + (reallyNotThere 2 == "" ) +
"<br>");
Response.Write( "reallyNotThere 2 === \"\" - " + (reallyNotThere 2 === "" ) +
"<br>");
Response.Write( "reallyNotThere 2 == null - " + (reallyNotThere 2 == null ) +
"<br>");
Response.Write( "reallyNotThere 2 === null - " + (reallyNotThere 2 === null )
+ "<br>");
Response.Write( typeof(reallyNo tThere) + " - " + typeof(reallyNo tThere2)+
"<br>"),
Response.Write( "reallyNotT here is \"" + reallyNotThere + "\" - " +
"reallyNotThere 2 is \"" + reallyNotThere2 + "\"<br>");
if ("toString" in reallyNotThere2 ) {
Response.Write( "reallyNotThere 2 has a toString<br>");
} else {
Response.Write( "reallyNotThere 2 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********@rem ovethis.optusho me.com.au> wrote:
Hi Wagner,
I think the difference is that Session("really NotThere") returns null
and Request("really NotThere2") returns an empty string.

Try Response.Write( typeof(reallyNo tThere) + " - " +
typeof(reallyNo tThere2)), 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("really NotThere") ;
var reallyNotThere2 = Request("really NotThere") ;


I usually do this:
var reallyNotThere2 = String(Request( "reallyNotThere "));
if (reallyNotThere 2 == "" || 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 (reallyNotThere 2 == "" || 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
3122
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, 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
3
2238
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: (1) I want to count how many characters there is in a string. In ASP I just use <%=Len(Variabel)%> How do I do this in Jscript?
6
19233
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, but stop midway through with an error embeded in the page: "Microsoft JScript runtime error '800a138f' 'undefined' is null or not an object". The...
3
1590
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 contains a button, labeled "Process Now!" My goal is to examine the user's name and upload it into a database. Since all of the elements (the...
4
1942
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 activeX-2D-control. In codebehind, I use C# for the application logic (eg. the database access). The query to the database retuns me an object of a C#...
6
1850
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 contains data from a database query which is done in C# in codebehind. I create a jscript - script that is injected into the aspx-page. I need this...
2
7924
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 the submit button I receive the following error: Microsoft JScript runtime error '800a1391' 'MM_ITEmpStat_STRING' is undefined
1
4212
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"%> <!--#include virtual="/Connections/EmployeeStatusChange.asp" --> <%
2
2473
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 ArrayList to hold the com objects ought to work. If I add strings to the ArrayList and return the list, the JScript enumerator object works great...
1
3441
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
7620
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7931
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8139
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7985
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6298
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3659
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1230
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
959
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.