HOWTO Make CStr for JavaScript on ASP w/ Request.Form and QueryStr
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > IIS server support > IIS ASP > HOWTO Make CStr for JavaScript on ASP w/ Request.Form and QueryStr




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-22-07 12:20 AM

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 tha
t
the returned data is 100% turned into a string that JavaScript can work upon
.

Any ideas?






[ Post a follow-up to this message ]



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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-22-07 12:20 AM

"ATS" <ATS@discussions.microsoft.com> wrote in message
news:D0BA7279-D9BA-4FD0-91C6-C0A498D359DB@microsoft.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.)







[ Post a follow-up to this message ]



    Re: HOWTO Make CStr for JavaScript on ASP w/ Request.Form and QueryStr  
Anthony Jones


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-22-07 12:29 PM


"ATS" <ATS@discussions.microsoft.com> wrote in message
news:D0BA7279-D9BA-4FD0-91C6-C0A498D359DB@microsoft.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.








[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 07:20 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register