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

Discussion in 'ASP General' started by ATS, Mar 21, 2007.

  1. ATS

    ATS Guest

    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?
     
    ATS, Mar 21, 2007
    #1
    1. Advertising

  2. ATS

    McKirahan Guest

    "ATS" <> wrote in message
    news:D...
    > 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.)
     
    McKirahan, Mar 21, 2007
    #2
    1. Advertising

  3. "ATS" <> wrote in message
    news:D...
    > 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.
     
    Anthony Jones, Mar 22, 2007
    #3
  4. ATS

    ATS Guest

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

    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.
     
    ATS, Mar 22, 2007
    #4
  5. Re: HOWTO Make CStr for JavaScript on ASP w/ Request.Form and Quer

    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.
     
    Dave Anderson, Mar 22, 2007
    #5
  6. ATS

    ATS Guest

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

    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.
     
    ATS, Mar 23, 2007
    #6
  7. Re: HOWTO Make CStr for JavaScript on ASP w/ Request.Form and Quer

    "ATS" <> wrote in message
    news:...
    >
    > 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-us/iissdk/html/3c778166-4a3c-4eda-b7cd-bb8557fe2de0.asp

    In the same intuative place.
     
    Anthony Jones, Mar 23, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wilhelm Pieper

    HowTo: get request.form[i].name

    Wilhelm Pieper, Jul 6, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    610
    David Waz...
    Jul 6, 2003
  2. Brian Birtle
    Replies:
    2
    Views:
    2,036
    John Saunders
    Oct 16, 2003
  3. George
    Replies:
    5
    Views:
    6,616
    George
    Apr 2, 2004
  4. =?Utf-8?B?ZXN3YW5zb24=?=

    asp.net form to send a request to a put request

    =?Utf-8?B?ZXN3YW5zb24=?=, Oct 29, 2004, in forum: ASP .Net
    Replies:
    9
    Views:
    604
    =?Utf-8?B?ZWpz?=
    Nov 9, 2004
  5. Michael Lawson

    Concerning string.cstr()

    Michael Lawson, Oct 28, 2003, in forum: C++
    Replies:
    3
    Views:
    2,509
    Pierre
    Oct 28, 2003
Loading...

Share This Page