473,887 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript typeof checking a Request value

Hi All!

I have the following code in an asp page whose language tag is:
<%@LANGUAGE="JA VASCRIPT" CODEPAGE="65001 "%>

// Find request variables.
var edition = Request.Form ("edition");
var language = Request.Form ("language") ;
Response.Write( "Edition is type &quot;" + (typeof edition) + "&quot; and
value &quot;" + edition + "&quot;<br> ");
Response.Write( "Language is type &quot;" + (typeof language) + "&quot;
and value &quot;" + language + "&quot;<br> ");

if (edition == "undefined" ||
(typeof edition) == "undefined" )
{
Response.Write( "Choose Page<br>");
Server.Execute ("choosePage.as p");
} // end if
else
{
Response.Write( "View Page<br>");
Server.Execute ("viewPage.asp" );
} // end else

The problem is this is what I see:

Edition is type "object" and value "undefined"
Language is type "object" and value "undefined"
View Page
There is nothing in choosePage.asp or viewPage.asp yet, but I am unable to
figure out why the else is triggering and not the if - my print out of the
edition var shows it has a value of "undefined" ...

Any help would be most appreciated!

Rob
:)
Jul 19 '05 #1
8 10026
"Robert Mark Bram" <re********@rem ovethis.optusho me.com.au> writes:
Response.Write( "Edition is type &quot;" + (typeof edition) + "&quot; and
value &quot;" + edition + "&quot;<br> "); .... if (edition == "undefined" ||
(typeof edition) == "undefined" ) .... Edition is type "object" and value "undefined"
So, edition is an *object*, and when it is converted to a string, it
becomes the string "undefined" . I.e., edition.toStrin g() == "undefined" .

You then test whether edition=="undef ined" . It isn't, since it is an
object, not a string, and objects are only equal to themselves.

Likewise, (typeof edition)=="unde fined" fails since (typeof
edition)=="obje ct".
but I am unable to figure out why the else is triggering and not the
if - my print out of the edition var shows it has a value of
"undefined" ...


No, its value is an object, which is neither the value "undefined" or
the string "undefined" . That object has a method called toString that
returns the string "undefined" .

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 19 '05 #2
> I have the following code in an asp page whose language tag is:
<%@LANGUAGE="JA VASCRIPT" CODEPAGE="65001 "%>

// Find request variables.
var edition = Request.Form ("edition");
var language = Request.Form ("language") ;
I think you probably want the String value stored in the Request.Form.It em
object, not the object itself.
Try
var edition = String (Request.Form ("edition")) ,
language = String (Request.Form ("language") );

The variables should now contain either the string value from the form
field, or the string "undefined" .

I hope this helps. I don't often see server-side JScript questions here,
most people seem to think that if it's ASP then it must be VBS.

MightyC

PS. I hope your user never types in "undefined" as a value!
Response.Write( "Edition is type &quot;" + (typeof edition) + "&quot; and...(snipped)

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.520 / Virus Database: 318 - Release Date: 18/09/03
Jul 19 '05 #3
Hi MightyC! :)

Thanks for the response!
var edition = String (Request.Form ("edition")) ,
language = String (Request.Form ("language") );
OK, well this gets out the values as Strings..
I hope this helps. I don't often see server-side JScript questions here,
most people seem to think that if it's ASP then it must be VBS.
I spent a lot of time learning Javascript - I want to keep using it!
PS. I hope your user never types in "undefined" as a value!


How on earth am I going to get around this?

Why isn't this a problem with VBScript?

Rob
:)
Jul 19 '05 #4
> Thanks for the response!

You're welcome!
var edition = String (Request.Form ("edition")) ,
language = String (Request.Form ("language") );
OK, well this gets out the values as Strings..


It will invoke the toString method for the object, which is what you want.
I hope this helps. I don't often see server-side JScript questions here,
most people seem to think that if it's ASP then it must be VBS.


I spent a lot of time learning Javascript - I want to keep using it!


Amen to that!
PS. I hope your user never types in "undefined" as a value!


How on earth am I going to get around this?


I use code like this:

var action = (typeof (Request.Form.I tem ("action")) == "undefined" )
? null
: String (Request.Form.I tem ("action"));

It's a bit clumsy but I've never come up with anything better. Now you can
test for empty field (ie. == null) and use a default value or send an error
or whatever.
Why isn't this a problem with VBScript?


Dunno. Never used VBScript :)

Happy JavaScript
MightyC

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.520 / Virus Database: 318 - Release Date: 18/09/03
Jul 19 '05 #5
Hi again!
I use code like this:

var action = (typeof (Request.Form.I tem ("action")) == "undefined" )
? null
: String (Request.Form.I tem ("action"));


Except that I am finding this:
typeof (Request ("notThere") )
or
typeof (Request.Form.I tem ("notThere") )
returns
"object"

and not "undefined"

Rob
:)
Jul 19 '05 #6
On Sun, 19 Oct 2003 12:28:15 +1000, "Robert Mark Bram"
<re********@rem ovethis.optusho me.com.au> wrote:
Hi again!
I use code like this:

var action = (typeof (Request.Form.I tem ("action")) == "undefined" )
? null
: String (Request.Form.I tem ("action"));


Except that I am finding this:
typeof (Request ("notThere") )
or
typeof (Request.Form.I tem ("notThere") )
returns
"object"

and not "undefined"


Yes, that's correct, it's a collection. As I said in your other
thread I usually just convert it to a string immediately and handle
undefined later. However, this is the "proper" way to do it:

var foo = Request.Form("f oo").Count == 0
? null
: Request.Form("f oo").item()

item() will return a string of all the foo arguments concatenated
together and delimited by commas, for example, if you have
?foo=123&foo=45 6 then .item() will return "123, 456". If you could
potentially have multiple instances of the same argument and the value
may contain a comma then you should loop through the collection using
..item(i), which returns the i-th foo argument, to be sure you handle
the values correctly.

Regards,
Steve
Jul 19 '05 #7
On Sat, 18 Oct 2003 22:04:04 +0000 (UTC), "The Mighty Chaffinch"
<mi************ *@hotmail.com> wrote:
> var edition = String (Request.Form ("edition")) ,
> language = String (Request.Form ("language") );


OK, well this gets out the values as Strings..


It will invoke the toString method for the object, which is what you want.


These are not JScript objects; they don't have a toString() method.
String(edition) calls the default method for the object which, in this
case, happens to be item().

Regards,
Steve
Jul 19 '05 #8
Howdy Steve - thank you very much for your response!

(from your other reply)
These are not JScript objects; they don't have a toString() method.
String(edition) calls the default method for the object which, in this
case, happens to be item().
*the fog begins to lift* .. :)
Yes, that's correct, it's a collection. .... var foo = Request.Form("f oo").Count == 0
? null
: Request.Form("f oo").item()


Now that I see it is a collection, this is exactly what I wanted!

Rob
:)
Jul 19 '05 #9

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

Similar topics

0
9799
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11173
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10770
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9593
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7141
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4632
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
2
4238
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3245
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.