473,761 Members | 2,824 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("N AME") and Request.QuerySt ring("NAME")
as such:
Post to this page as: TST.asp?STATE=T EST
<%@ Language=JavaSc ript %>
<%
Response.AddHea der("Pragma", "No-Cache");
%>
<%
var oThis = Request.Form("S TATE");
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("N AME") and Request.QuerySt ring("NAME") do not seem to have them.

What can be done?
Mar 21 '07 #1
5 5905
=?Utf-8?B?QVRT?= wrote on 21 mrt 2007 in
microsoft.publi c.inetserver.as p.general:
<%
var oThis = Request.Form("S TATE");
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=JavaSc ript %>
<%
var csResults = Request.Form("s tate");
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=JavaSc ript %>
<%
Response.AddHea der("Pragma", "No-Cache");
%>
<%
var csTST = " ==>" + Request.Form("S TATE") + "<==";
%>
<html>
<%=csTST%>
</html>

I get this:

==>undefinded<= =

Strangely, if I do this:

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

I get a nice blank.

The issue is that the ASP/JavaScript is not returning a string for
Request.Form("S TATE"). 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.publi c.inetserver.as p.general:
Thanks for the reply, but it is not working.

When I try this:

<%@ Language=JavaSc ript %>
<%
Response.AddHea der("Pragma", "No-Cache");
%>
<%
var csTST = " ==>" + Request.Form("S TATE") + "<==";
%>
<html>
<%=csTST%>
</html>

I get this:

==>undefinded<= =

Strangely, if I do this:

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

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

Try:

<%@ Language=JavaSc ript %>
<%
var csResults = Request.Form("s tate");
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.QuerySt ring with JavaScript, one needs to use
".Item" to make it return the string or undefined/null object.

Example:

var csTST = Request.Form("S TATE").Item;

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

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

Example:

var csTST = Request.Form("S TATE").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
3353
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? The following page2.asp won't output the value entered in page1.asp. However, if we do <form action="page2.asp" method="get" target="_blank">, then it will open a new window for the request page, instead of using the same window as page1.asp....
3
2304
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 need to: 1. Click a submit button on an asp page, calling another page that saves the contents of that form to a database and then displays
12
8163
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 that the apostrophe is automatically replace with two '' . Reason being--SQL Server does not like apostrophes being sent to database. I've tried to do this on the server side in the SQL area of the ASP page by writing a function (with some great...
19
6931
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 JavaScript in this code from a couple different sites but I'm not 100% sure what each line is doing...This is the ASP code that I'm using for the page....Take a look at the JavaScript code and please let me know what each line is doing....I have been...
7
1871
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 submit button, but when I'm getting the form collection (using post or get (form/querystring) I can't retrieve that
3
2097
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 the original form to correct the input. This all works fine until I try to incorporate a javascript to display a popup calendar which posts the selected date back to a field on the form. This script works fine in itself, however if the page is...
7
9662
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 operation on parameters not passed. Example: Make a TST.asp and post to it as TST.asp?STATE=TEST <%@ Language=JavaScript %> <%
6
14095
by: magix | last post by:
Hi, Can I: <script language="javascript"> var TimeSec = new String (Request.form("TimeInSec")); or
2
5109
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 design before all the CGI and PHP stuff got big, so I prefer to do things simply. The form worked fine, emails the results like perfect, but it refused to redirect the page to the confirmation. I thought I could add an onClick to the submit button,...
0
9377
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
10136
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...
1
9925
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8814
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
6640
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
5266
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...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
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.