473,406 Members | 2,954 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.

HOWTO Make CStr for JavaScript on ASP w/ Request.Form and QueryStr

HOWTO Make CStr for JavaScript on ASP w/ Request.Form and QueryString

In ASP, Request.Form and Request.QueryString return objects that do not
support "toString", or any JavaScript string operation on parameters not
passed.

Example: Make a TST.asp and post to it as TST.asp?STATE=TEST

<%@ Language=JavaScript %>
<%
Response.AddHeader("Pragma", "No-Cache");
%>
<html>
<%
var csTST = Request.Form("STATE");

if ((csTST == "") || (typeof(csTST) == "undefined"))
{
%>
Request.Form("STATE") is NULL/Empty/Blank<br>
<%
}
else
{
%>
Request.Form("STATE") = "<%=csTST%>"<br>
<%
}

csTST = Request.QueryString("STATE");

if ((csTST == "") || (typeof(csTST) == "undefined"))
{
%>
Request.QueryString("STATE") is NULL/Empty/Blank<br>
<%
}
else
{
%>
Request.QueryString("STATE") = "<%=csTST%>"<br>
<%
}
%>
</html>

From this sample, the output will be as such:

Request.Form("STATE") = ""
Request.QueryString("STATE") = "REGISTER"

This is WRONG. The Request.Form is blank, but yet, the test for "" and even
typeof failed to detect it. What I want is some kind of CStr function so that
the returned data is 100% turned into a string that JavaScript can work upon.

Any ideas?

Mar 21 '07 #1
7 9631
"ATS" <AT*@discussions.microsoft.comwrote in message
news:D0**********************************@microsof t.com...
HOWTO Make CStr for JavaScript on ASP w/ Request.Form and QueryString

In ASP, Request.Form and Request.QueryString return objects that do not
support "toString", or any JavaScript string operation on parameters not
passed.

Example: Make a TST.asp and post to it as TST.asp?STATE=TEST

<%@ Language=JavaScript %>
<%
Response.AddHeader("Pragma", "No-Cache");
%>
<html>
<%
var csTST = Request.Form("STATE");

if ((csTST == "") || (typeof(csTST) == "undefined"))
{
%>
Request.Form("STATE") is NULL/Empty/Blank<br>
<%
}
else
{
%>
Request.Form("STATE") = "<%=csTST%>"<br>
<%
}

csTST = Request.QueryString("STATE");

if ((csTST == "") || (typeof(csTST) == "undefined"))
{
%>
Request.QueryString("STATE") is NULL/Empty/Blank<br>
<%
}
else
{
%>
Request.QueryString("STATE") = "<%=csTST%>"<br>
<%
}
%>
</html>

From this sample, the output will be as such:

Request.Form("STATE") = ""
Request.QueryString("STATE") = "REGISTER"

This is WRONG. The Request.Form is blank, but yet, the test for "" and
even
typeof failed to detect it. What I want is some kind of CStr function so
that
the returned data is 100% turned into a string that JavaScript can work
upon.
>
Any ideas?
Adding this returns what you expect:

<form method="post">
<input type="text" name="STATE" value="">
<input type="submit" value="Submit">
</form>

This too: http://localhost/temp/TST.asp?STATE=

(If I understand you correctly.)
Mar 21 '07 #2

"ATS" <AT*@discussions.microsoft.comwrote in message
news:D0**********************************@microsof t.com...
HOWTO Make CStr for JavaScript on ASP w/ Request.Form and QueryString

In ASP, Request.Form and Request.QueryString return objects that do not
support "toString", or any JavaScript string operation on parameters not
passed.

Example: Make a TST.asp and post to it as TST.asp?STATE=TEST

<%@ Language=JavaScript %>
<%
Response.AddHeader("Pragma", "No-Cache");
%>
<html>
<%
var csTST = Request.Form("STATE");

if ((csTST == "") || (typeof(csTST) == "undefined"))
{
%>
Request.Form("STATE") is NULL/Empty/Blank<br>
<%
}
else
{
%>
Request.Form("STATE") = "<%=csTST%>"<br>
<%
}

csTST = Request.QueryString("STATE");

if ((csTST == "") || (typeof(csTST) == "undefined"))
{
%>
Request.QueryString("STATE") is NULL/Empty/Blank<br>
<%
}
else
{
%>
Request.QueryString("STATE") = "<%=csTST%>"<br>
<%
}
%>
</html>

From this sample, the output will be as such:

Request.Form("STATE") = ""
Request.QueryString("STATE") = "REGISTER"

This is WRONG. The Request.Form is blank, but yet, the test for "" and
even
typeof failed to detect it. What I want is some kind of CStr function so
that
the returned data is 100% turned into a string that JavaScript can work
upon.
>
Any ideas?
You need to bear in mind that that both form and querystring fields can be
multivalued hence both actual return an indexable object. The objects
returned have an Item indexer property that is marked as the default
property. In VBScript whether to access this default property or not is
determined by whether the assignment is prefixed with the Set keyword. In
JScript default properties are ignored and the object reference is always
passed.

Hence in the code above it doesn't matter what name you pass to QueryString
or Form you will always get an object back. I.E. typeof(csTest) ==
'object' will always be true.

Use code like this:-

csTST = Request.QueryString("STATE").Item // note the additional explicit
use of Item.

Now with no state in the query string then typeof(csTST) == 'undefined' is
true.

With ?state= then typeof(csTST) == 'string' is true and csTST == "" is
true.

With ?state=NY then typeof(csTST) == 'string' is true and csTST == "" is
false.

Personally I would just use:-

if (csTest)
{

}

in my code.

Mar 22 '07 #3
Thanks Anthony, this helps,

All that was needed was the ".Item".

Sadly, nowhere in the ASP/IIS documentation is that mentioned. And it makes
a HUGE difference.

Mar 22 '07 #4
ATS wrote:
All that was needed was the ".Item".

Sadly, nowhere in the ASP/IIS documentation is that mentioned.
And it makes a HUGE difference.
Yes, it does. That is one of the many reasons why I suggest people use
Visual Studio when writing ASP in JScript -- even though the documentation
tell you nothing, Intellisense tells you plenty about the structure of
objects. And Visual Web Developer Express is free!

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Mar 22 '07 #5

Actually, no, in our Visual Studio 2003, with the MSDN, dated July 2004,
there is no documentation anywheres about the Request.Form or
Request.QueryString.

Maybe in later MSDN's or later VisualStudio's it does, but ours does not.
Mar 23 '07 #6

"ATS" <AT*@discussions.microsoft.comwrote in message
news:9A**********************************@microsof t.com...
>
Actually, no, in our Visual Studio 2003, with the MSDN, dated July 2004,
there is no documentation anywheres about the Request.Form or
Request.QueryString.

Maybe in later MSDN's or later VisualStudio's it does, but ours does not.
I'm use VS 2003 with the supplied MSDN installed.

On my system the docs are found here (bet if you tweak 2003FEB to 2004JUL
it'd work on yours)

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/iisref/htm/ref_vbom_reqocqs.h
tm

It's natural to expect to find this documentation under Server Tech / Active
Server Pages but nooo!

You have to go through Server Tech -IIS ->SDK ->IIS -Reference ->IIS
Development -ASP Ref.
Intuative huh?

Online it's here:-

http://msdn.microsoft.com/library/en...8557fe2de0.asp

In the same intuative place.



Mar 23 '07 #7
[Please quote on USENET]

"ATS" wrote:
Actually, no, in our Visual Studio 2003, with the MSDN, dated July
2004, there is no documentation anywheres about the Request.Form
or Request.QueryString.
I did not say the Visual Studio documentation said anything about it. I said
that Intellisense does.


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.

Mar 23 '07 #8

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

Similar topics

12
by: Barnes | last post by:
Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form? Here is the scenario: I have a form that cannot accept apostrophes. I want to use the replace() so...
1
by: Neil Sandow | last post by:
My site with servers located on the West Coast runs ads served by an adserver on the East Coast. A not infrequent problem occurs when a user on the West Coast tries to load a page but for whatever...
3
by: PVU | last post by:
Hello, I have an page that calls the function below. What i want to do is that this function post data to the server (ASP) and the server will response with 'OK' My question is how can i send...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
5
by: Wilhelm Pieper | last post by:
Hello, HowTo: catch name/value pairs from request.form? My viewstate shows: "__VIEWSTATE=..&111=5.." I want to get this pairs of IDs/names and values . But because the DropDownList ist...
7
by: Bruno Alexandre | last post by:
Hi guys, Sorry about the off topic, but I can't find the ASP group just the ASP dot NET If I want to block a user to change a form after submiting, I add a function that will disable the...
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
3
by: anthonybrough | last post by:
I have an asp page that has a form to collect user data in a form. when the user clicks submit the input is validated. If any fields are not acceptable the user clicks on a button to go back to...
6
by: fnoppie | last post by:
Hi, I am near to desperation as I have a million things to get a solution for my problem. I have to post a multipart message to a url that consists of a xml file and an binary file (pdf)....
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
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...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.