473,404 Members | 2,213 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,404 software developers and data experts.

PRB JavaScript in ASP with Request.Form

PRB JavaScript in ASP with Request.Form

Please help,

I'm having a problem with JavaScript in ASP, where the ASP page crashes when
I try to determine if data was posted from a FORM or through a QueryString.
Where, if the data came through via a FORM, I want to use it 1st, but if not,
to then try using it from the QueryString. Basically, the problem boils down
to using "toString()" on Request.Form("NAME") and Request.QueryString("NAME")
as such:
Post to this page as: TST.asp?STATE=TEST
<%@ Language=JavaScript %>
<%
Response.AddHeader("Pragma", "No-Cache");
%>
<%
var oThis = Request.Form("STATE");
var csResults;

if ((oThis == null) || (typeof(oThis) == "undefined"))
{
csResults = "NULL";
}
else
{
csResults = oThis.toString(); // ASP Crashes here. Why?!??!
}
%>
<html>
<%=csResults%>
</html>

That code crashes at the "toString()" call, which should not be. JavaScript
says all "Object" types have "toString" in them, but both
Request.Form("NAME") and Request.QueryString("NAME") do not seem to have them.

What can be done?
Mar 21 '07 #1
5 5878
=?Utf-8?B?QVRT?= wrote on 21 mrt 2007 in
microsoft.public.inetserver.asp.general:
<%
var oThis = Request.Form("STATE");
var csResults;

if ((oThis == null) || (typeof(oThis) == "undefined"))
{
csResults = "NULL";
}
else
{
csResults = oThis.toString(); // ASP Crashes here. Why?!??!
}
%>
<html>
<%=csResults%>
</html>
The result of Request.Form() is always a string,
and if not existing can be represented by an empty string. So:

<%@ Language=JavaScript %>
<%
var csResults = Request.Form("state");
if (csResults == "") csResults = "NULL";
%>
<%=csResults%>

should meet your requirements, methinks.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 21 '07 #2
Thanks for the reply, but it is not working.

When I try this:

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

I get this:

==>undefinded<==

Strangely, if I do this:

var csTST = Request.Form("STATE") ;
..
..
<%=csTST%>

I get a nice blank.

The issue is that the ASP/JavaScript is not returning a string for
Request.Form("STATE"). In fact, using "typeof(Request.Form("STATE"))" returns
"object". Is there any kind of CStr function available like in VB? By the
way, I do not want to switch to VBScript.

Mar 21 '07 #3
=?Utf-8?B?QVRT?= wrote on 21 mrt 2007 in
microsoft.public.inetserver.asp.general:
Thanks for the reply, but it is not working.

When I try this:

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

I get this:

==>undefinded<==

Strangely, if I do this:

var csTST = Request.Form("STATE") ;
.
.
<%=csTST%>

I get a nice blank.
You are right, but please always quote on usenet, this is not email.

Try:

<%@ Language=JavaScript %>
<%
var csResults = Request.Form("state");
if (''+csResults == 'undefined') csResults = 'NULL';
if (csResults == '') csResults = 'EMPTY';
%>

<% = csResults %>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 21 '07 #4
Thanks Evertjan for helping, but I found the problem.

With Request.Form and Request.QueryString with JavaScript, one needs to use
".Item" to make it return the string or undefined/null object.

Example:

var csTST = Request.Form("STATE").Item;

Mar 22 '07 #5
=?Utf-8?B?QVRT?= wrote on 22 mrt 2007 in
microsoft.public.inetserver.asp.general:
Thanks Evertjan for helping, but I found the problem.

With Request.Form and Request.QueryString with JavaScript, one needs
to use ".Item" to make it return the string or undefined/null object.

Example:

var csTST = Request.Form("STATE").Item;

Well done!

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 22 '07 #6

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

Similar topics

1
by: Matt | last post by:
My problem is when the user click the submit button, it will launch another new window for the request page. I want to confirm we cannot use JavaScript open window functions to open a request page?...
3
by: fig000 | last post by:
Hi, I'm relatively new to Javascript so please bear with me on what might sound like silly questions. This is what I want to do: I'm working in classic asp (I have to for this project). I...
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...
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...
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...
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...
7
by: =?Utf-8?B?QVRT?= | last post by:
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...
6
by: magix | last post by:
Hi, Can I: <script language="javascript"> var TimeSec = new String (Request.form("TimeInSec")); or
2
by: Rahina | last post by:
I am working in Dreamweaver 8, and I have created a simple form: http://www.realmofmystery.com/app.html This is a free website I am doing for some friends, so nothing fancy. And, I learned web...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.