PRB JavaScript in ASP with Request.Form

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

  1. ATS

    ATS Guest

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

  2. ATS

    Evertjan. Guest

    =?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)
    Evertjan., Mar 21, 2007
    #2
    1. Advertising

  3. ATS

    ATS Guest

    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.
    ATS, Mar 21, 2007
    #3
  4. ATS

    Evertjan. Guest

    =?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)
    Evertjan., Mar 21, 2007
    #4
  5. ATS

    Evertjan. Guest

    =?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)
    Evertjan., Mar 22, 2007
    #5
    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. Patricia Kline
    Replies:
    1
    Views:
    569
    Oliver
    Oct 25, 2003
  2. Miguel Angel Dinelli
    Replies:
    1
    Views:
    442
    Chris Jackson
    Nov 13, 2003
  3. Mike Hofer

    PRB: Webcontrol Property Lost On Build

    Mike Hofer, Jul 10, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    441
    Mike Hofer
    Jul 11, 2005
  4. Venkatesh

    Pointer to Class prb

    Venkatesh, Apr 30, 2004, in forum: C++
    Replies:
    8
    Views:
    327
  5. Venkatesh

    Pointer to Class prb

    Venkatesh, May 4, 2004, in forum: C++
    Replies:
    2
    Views:
    271
    Karl Heinz Buchegger
    May 4, 2004
Loading...

Share This Page